Skip to content

Commit 17b1089

Browse files
committed
Pagination accessors should react to filter state
1 parent f36e52e commit 17b1089

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

.changeset/fuzzy-ducks-grab.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@careswitch/svelte-data-table': patch
3+
---
4+
5+
Pagination accessors should react to filter state

src/lib/DataTable.svelte.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ export class DataTable<T> {
206206
* @returns {number} The total number of pages.
207207
*/
208208
get totalPages() {
209+
// React to changes in filter state
210+
this.#filterState;
211+
this.#globalFilterRegex;
212+
209213
this.#applyFilters();
210214
return Math.max(1, Math.ceil(this.#filteredData.length / this.#pageSize));
211215
}
@@ -230,6 +234,10 @@ export class DataTable<T> {
230234
* @returns {boolean} True if there's a previous page available, false otherwise.
231235
*/
232236
get canGoBack() {
237+
// React to changes in filter state
238+
this.#filterState;
239+
this.#globalFilterRegex;
240+
233241
return this.currentPage > 1 && this.#filteredData.length > 0;
234242
}
235243

@@ -238,6 +246,10 @@ export class DataTable<T> {
238246
* @returns {boolean} True if there's a next page available, false otherwise.
239247
*/
240248
get canGoForward() {
249+
// React to changes in filter state
250+
this.#filterState;
251+
this.#globalFilterRegex;
252+
241253
return this.currentPage < this.totalPages && this.#filteredData.length > 0;
242254
}
243255

0 commit comments

Comments
 (0)