File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -39,8 +39,8 @@ export interface PaginationDirectiveConfiguration<T> {
39
39
40
40
export const paginationDirective = < T > ( { table} : PaginationDirectiveConfiguration < T > ) : PaginationDirective => {
41
41
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 ;
44
44
45
45
const proxy = < PaginationProxy > sliceListener ( { emitter : table } ) ;
46
46
@@ -72,8 +72,8 @@ export const paginationDirective = <T>({table}: PaginationDirectiveConfiguration
72
72
directive . onSummaryChange ( ( { page : p , size : s , filteredCount} : Summary ) => {
73
73
currentPage = p ;
74
74
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 ;
77
77
} ) ;
78
78
79
79
return directive ;
Original file line number Diff line number Diff line change @@ -83,4 +83,11 @@ export default ({test}) => {
83
83
table . dispatch ( evts . SUMMARY_CHANGED , { page : 1 , size : 0 } ) ;
84
84
t . deepEqual ( dir . state ( ) . pageCount , 1 ) ;
85
85
} ) ;
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
+ }
You can’t perform that action at this time.
0 commit comments