diff --git a/src/components/SearchInput/SearchInput.svelte b/src/components/SearchInput/SearchInput.svelte
index c89a83dc..929a0e85 100644
--- a/src/components/SearchInput/SearchInput.svelte
+++ b/src/components/SearchInput/SearchInput.svelte
@@ -6,15 +6,23 @@
interface Props {
/** The placeholder text that appears in the search box.*/
searchPlaceholder?: string;
+
+ onsearch?: (newValue: string) => void;
}
- let { searchPlaceholder = 'Search...' }: Props = $props();
+ let { searchPlaceholder = 'Search...', onsearch }: Props = $props();
let value = $state('');
let active = $derived(value !== '');
function clear() {
value = '';
+ if (onsearch) onsearch(value); // Call the prop to update the parent when cleared
+ }
+
+ function oninput(event: Event) {
+ value = (event.target as HTMLInputElement).value;
+ if (onsearch) onsearch(value); // Update the parent on every input change
}
@@ -22,12 +30,14 @@
+
\ No newline at end of file
+
diff --git a/src/components/Table/Table.svelte b/src/components/Table/Table.svelte
index 600a53e2..e961a7f4 100644
--- a/src/components/Table/Table.svelte
+++ b/src/components/Table/Table.svelte
@@ -1,5 +1,5 @@
-
@@ -212,10 +219,7 @@
{/if}
{#if searchable}
-
+
{/if}
diff --git a/src/components/Table/utils.ts b/src/components/Table/utils.ts
index 5892ab6d..be9357e5 100644
--- a/src/components/Table/utils.ts
+++ b/src/components/Table/utils.ts
@@ -1,8 +1,12 @@
-export function filterArray(
- data: T[],
+type FilterableDatum> = T & {
+ searchStr: string;
+};
+
+export function filterArray>(
+ data: FilterableDatum[],
searchText: string,
- filterField: keyof T,
- filterValue: T[keyof T]
+ filterField: keyof FilterableDatum,
+ filterValue: FilterableDatum[keyof FilterableDatum]
) {
if (searchText) {
data = data.filter((item) => {
@@ -12,13 +16,14 @@ export function filterArray(
if (filterValue) {
data = data.filter((item) => {
+ if (!filterField) return true; // or handle the undefined case as appropriate
+
return item[filterField] === filterValue;
});
}
return data;
}
-
export function paginateArray(
array: T[],
pageSize: number,