Skip to content

Commit 5c7aa86

Browse files
authored
feat: add onItemsChange callback to PaginatedTable (#3300)
Adds an optional onItemsChange callback prop that fires whenever the visible items change (page navigation, fetch, page size change). Enables consumers to react to table data changes without relying on slot prop workarounds.
1 parent c983481 commit 5c7aa86

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/lib/holocene/table/paginated-table/api-paginated.svelte

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
maxHeight?: string;
3333
onError?: ((error: Error | unknown) => void) | undefined;
3434
onFetch: () => Promise<PaginatedRequest<T>>;
35+
onItemsChange?: (items: T[]) => void;
3536
onShiftUp?: KeyboardHandler;
3637
onShiftDown?: KeyboardHandler;
3738
onSpace?: KeyboardHandler;
@@ -51,6 +52,7 @@
5152
export let maxHeight = '';
5253
export let onError: ((error: Error) => void) | undefined = undefined;
5354
export let onFetch: () => Promise<PaginatedRequest<T>>;
55+
export let onItemsChange: ((items: T[]) => void) | undefined = undefined;
5456
export let onShiftUp: KeyboardHandler = undefined;
5557
export let onShiftDown: KeyboardHandler = undefined;
5658
export let onSpace: KeyboardHandler = undefined;
@@ -182,6 +184,12 @@
182184
}
183185
}
184186
187+
let previousItems: T[] | undefined;
188+
$: if (onItemsChange && $store.visibleItems !== previousItems) {
189+
previousItems = $store.visibleItems;
190+
onItemsChange($store.visibleItems);
191+
}
192+
185193
$: adjustedTotal =
186194
!$store.hasNext && $store.indexEnd !== total ? $store.indexEnd : total;
187195
</script>

0 commit comments

Comments
 (0)