Skip to content

Commit 545dcce

Browse files
committed
Fix page count when filteredCount is falsy
1 parent 5b63a35 commit 545dcce

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/directives/pagination.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export interface PaginationDirectiveConfiguration<T> {
3939

4040
export const paginationDirective = <T>({table}: PaginationDirectiveConfiguration<T>): PaginationDirective => {
4141
let {slice: {page: currentPage, size: currentSize}} = table.getTableState();
42-
let itemListLength = table.filteredCount;
43-
let pageCount = currentSize ? Math.ceil(itemListLength / currentSize) : 1;
42+
let itemListLength = table.filteredCount || 0;
43+
let pageCount = currentSize && itemListLength ? Math.ceil(itemListLength / currentSize) : 1;
4444

4545
const proxy = <PaginationProxy>sliceListener({emitter: table});
4646

@@ -72,8 +72,8 @@ export const paginationDirective = <T>({table}: PaginationDirectiveConfiguration
7272
directive.onSummaryChange(({page: p, size: s, filteredCount}: Summary) => {
7373
currentPage = p;
7474
currentSize = s;
75-
itemListLength = filteredCount;
76-
pageCount = currentSize ? Math.ceil(itemListLength / currentSize) : 1;
75+
itemListLength = filteredCount || 0;
76+
pageCount = currentSize && itemListLength ? Math.ceil(itemListLength / currentSize) : 1;
7777
});
7878

7979
return directive;

test/directives/pagination.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,11 @@ export default ({test}) => {
8383
table.dispatch(evts.SUMMARY_CHANGED, {page: 1, size: 0});
8484
t.deepEqual(dir.state().pageCount, 1);
8585
});
86-
}
86+
test('pagination directive accepts falsy value for filteredCount', t => {
87+
const table = fakeTable({page: 1, size: 1});
88+
const dir = pagination({table});
89+
t.deepEqual(dir.state().pageCount, 1);
90+
table.dispatch(evts.SUMMARY_CHANGED, {page: 1, size: 1, filteredCount: 0});
91+
t.deepEqual(dir.state().pageCount, 1);
92+
});
93+
}

0 commit comments

Comments
 (0)