Skip to content

Commit

Permalink
Pagination accessors should react to filter state
Browse files Browse the repository at this point in the history
  • Loading branch information
pheuter committed Jul 16, 2024
1 parent f36e52e commit 17b1089
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-ducks-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@careswitch/svelte-data-table': patch
---

Pagination accessors should react to filter state
12 changes: 12 additions & 0 deletions src/lib/DataTable.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export class DataTable<T> {
* @returns {number} The total number of pages.
*/
get totalPages() {
// React to changes in filter state
this.#filterState;
this.#globalFilterRegex;

this.#applyFilters();
return Math.max(1, Math.ceil(this.#filteredData.length / this.#pageSize));
}
Expand All @@ -230,6 +234,10 @@ export class DataTable<T> {
* @returns {boolean} True if there's a previous page available, false otherwise.
*/
get canGoBack() {
// React to changes in filter state
this.#filterState;
this.#globalFilterRegex;

return this.currentPage > 1 && this.#filteredData.length > 0;
}

Expand All @@ -238,6 +246,10 @@ export class DataTable<T> {
* @returns {boolean} True if there's a next page available, false otherwise.
*/
get canGoForward() {
// React to changes in filter state
this.#filterState;
this.#globalFilterRegex;

return this.currentPage < this.totalPages && this.#filteredData.length > 0;
}

Expand Down

0 comments on commit 17b1089

Please sign in to comment.