@@ -38,6 +38,7 @@ export interface PaginatedTableProps<T, F> {
38
38
renderErrorMessage ?: RenderErrorMessage ;
39
39
containerClassName ?: string ;
40
40
onDataFetched ?: ( data : PaginatedTableData < T > ) => void ;
41
+ keepCache ?: boolean ;
41
42
}
42
43
43
44
const DEFAULT_PAGINATION_LIMIT = 20 ;
@@ -46,7 +47,7 @@ export const PaginatedTable = <T, F>({
46
47
limit : chunkSize = DEFAULT_PAGINATION_LIMIT ,
47
48
initialEntitiesCount,
48
49
fetchData,
49
- filters,
50
+ filters : rawFilters ,
50
51
tableName,
51
52
columns,
52
53
getRowClassName,
@@ -59,6 +60,7 @@ export const PaginatedTable = <T, F>({
59
60
renderEmptyDataMessage,
60
61
containerClassName,
61
62
onDataFetched,
63
+ keepCache = true ,
62
64
} : PaginatedTableProps < T , F > ) => {
63
65
const initialTotal = initialEntitiesCount || 0 ;
64
66
const initialFound = initialEntitiesCount || 1 ;
@@ -78,6 +80,13 @@ export const PaginatedTable = <T, F>({
78
80
chunkSize,
79
81
} ) ;
80
82
83
+ // this prevent situation when filters are new, but active chunks is not yet recalculated (it will be done to the next rendrer, so we bring filters change on the next render too)
84
+ const [ filters , setFilters ] = React . useState ( rawFilters ) ;
85
+
86
+ React . useEffect ( ( ) => {
87
+ setFilters ( rawFilters ) ;
88
+ } , [ rawFilters ] ) ;
89
+
81
90
const lastChunkSize = React . useMemo ( ( ) => {
82
91
// If foundEntities = 0, there will only first chunk
83
92
// Display it with 1 row, to display empty data message
@@ -107,7 +116,7 @@ export const PaginatedTable = <T, F>({
107
116
if ( parentRef ?. current ) {
108
117
parentRef . current . scrollTo ( 0 , 0 ) ;
109
118
}
110
- } , [ filters , initialFound , initialTotal , parentRef ] ) ;
119
+ } , [ rawFilters , initialFound , initialTotal , parentRef ] ) ;
111
120
112
121
const renderChunks = ( ) => {
113
122
return activeChunks . map ( ( isActive , index ) => (
@@ -127,6 +136,7 @@ export const PaginatedTable = <T, F>({
127
136
renderEmptyDataMessage = { renderEmptyDataMessage }
128
137
onDataFetched = { handleDataFetched }
129
138
isActive = { isActive }
139
+ keepCache = { keepCache }
130
140
/>
131
141
) ) ;
132
142
} ;
0 commit comments