penambahan fitur search
This commit is contained in:
@@ -55,6 +55,8 @@
|
|||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let search: string = "";
|
||||||
|
|
||||||
const columns: columns[] = [
|
const columns: columns[] = [
|
||||||
{ key: "no", title: "No. " },
|
{ key: "no", title: "No. " },
|
||||||
{ key: "employee_name", title: "Employee Name" },
|
{ key: "employee_name", title: "Employee Name" },
|
||||||
@@ -112,7 +114,7 @@
|
|||||||
|
|
||||||
// Tambahkan filter pencarian jika ada
|
// Tambahkan filter pencarian jika ada
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
query = query.ilike("emoloyee_name", `%${searchTerm}%`);
|
query = query.ilike("employee_name", `%${searchTerm}%`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Jalankan query
|
// Jalankan query
|
||||||
@@ -138,7 +140,7 @@
|
|||||||
currentPage = page;
|
currentPage = page;
|
||||||
offset = (currentPage - 1) * rowsPerPage;
|
offset = (currentPage - 1) * rowsPerPage;
|
||||||
|
|
||||||
fetchEmployee(null, "created_at", "desc", currentPage - 1, rowsPerPage);
|
fetchEmployee(search, "created_at", "desc", currentPage - 1, rowsPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
function pageRange(
|
function pageRange(
|
||||||
@@ -173,7 +175,7 @@
|
|||||||
currentPage = page;
|
currentPage = page;
|
||||||
offset = (currentPage - 1) * rowsPerPage;
|
offset = (currentPage - 1) * rowsPerPage;
|
||||||
|
|
||||||
fetchEmployee(null, "created_at", "desc", currentPage - 1, rowsPerPage);
|
fetchEmployee(search, "created_at", "desc", currentPage - 1, rowsPerPage);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -310,7 +312,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
await fetchEmployee(
|
await fetchEmployee(
|
||||||
null,
|
search,
|
||||||
"created_at",
|
"created_at",
|
||||||
"desc",
|
"desc",
|
||||||
(currentPage - 1) * rowsPerPage,
|
(currentPage - 1) * rowsPerPage,
|
||||||
@@ -330,7 +332,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fetchEmployee(
|
await fetchEmployee(
|
||||||
null,
|
search,
|
||||||
"created_at",
|
"created_at",
|
||||||
"desc",
|
"desc",
|
||||||
(currentPage - 1) * rowsPerPage,
|
(currentPage - 1) * rowsPerPage,
|
||||||
@@ -385,16 +387,21 @@
|
|||||||
placeholder="🔍 Search by item name..."
|
placeholder="🔍 Search by item name..."
|
||||||
class="border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none px-4 py-2 rounded-xl text-sm w-64 transition"
|
class="border border-gray-300 focus:ring-2 focus:ring-blue-500 focus:outline-none px-4 py-2 rounded-xl text-sm w-64 transition"
|
||||||
on:input={(e) => {
|
on:input={(e) => {
|
||||||
const searchTerm = (
|
search = (
|
||||||
e.target as HTMLInputElement
|
e.target as HTMLInputElement
|
||||||
).value.toLowerCase();
|
).value.toLowerCase();
|
||||||
fetchEmployee(searchTerm, "created_at", "desc");
|
|
||||||
|
if (search !== "" && search.length > 3) {
|
||||||
|
fetchEmployee(search, "created_at", "desc", 0, 10);
|
||||||
|
} else if (search === "") {
|
||||||
|
fetchEmployee(null, "created_at", "desc", 0, 10);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
class="bg-gray-200 text-gray-700 px-4 py-2 rounded-xl hover:bg-gray-300 text-sm transition"
|
class="bg-gray-200 text-gray-700 px-4 py-2 rounded-xl hover:bg-gray-300 text-sm transition"
|
||||||
on:click={() =>
|
on:click={() =>
|
||||||
fetchEmployee(null, "created_at", "desc", 0, 10)}
|
fetchEmployee(search, "created_at", "desc", 0, 10)}
|
||||||
>
|
>
|
||||||
🔄 Reset
|
🔄 Reset
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user