@@ -38,6 +38,7 @@ export interface PaginatedTableProps<T, F> {
3838 renderErrorMessage ?: RenderErrorMessage ;
3939 containerClassName ?: string ;
4040 onDataFetched ?: ( data : PaginatedTableData < T > ) => void ;
41+ keepCache ?: boolean ;
4142}
4243
4344const DEFAULT_PAGINATION_LIMIT = 20 ;
@@ -46,7 +47,7 @@ export const PaginatedTable = <T, F>({
4647 limit : chunkSize = DEFAULT_PAGINATION_LIMIT ,
4748 initialEntitiesCount,
4849 fetchData,
49- filters,
50+ filters : rawFilters ,
5051 tableName,
5152 columns,
5253 getRowClassName,
@@ -59,6 +60,7 @@ export const PaginatedTable = <T, F>({
5960 renderEmptyDataMessage,
6061 containerClassName,
6162 onDataFetched,
63+ keepCache = true ,
6264} : PaginatedTableProps < T , F > ) => {
6365 const initialTotal = initialEntitiesCount || 0 ;
6466 const initialFound = initialEntitiesCount || 1 ;
@@ -78,6 +80,13 @@ export const PaginatedTable = <T, F>({
7880 chunkSize,
7981 } ) ;
8082
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+
8190 const lastChunkSize = React . useMemo ( ( ) => {
8291 // If foundEntities = 0, there will only first chunk
8392 // Display it with 1 row, to display empty data message
@@ -107,7 +116,7 @@ export const PaginatedTable = <T, F>({
107116 if ( parentRef ?. current ) {
108117 parentRef . current . scrollTo ( 0 , 0 ) ;
109118 }
110- } , [ filters , initialFound , initialTotal , parentRef ] ) ;
119+ } , [ rawFilters , initialFound , initialTotal , parentRef ] ) ;
111120
112121 const renderChunks = ( ) => {
113122 return activeChunks . map ( ( isActive , index ) => (
@@ -127,6 +136,7 @@ export const PaginatedTable = <T, F>({
127136 renderEmptyDataMessage = { renderEmptyDataMessage }
128137 onDataFetched = { handleDataFetched }
129138 isActive = { isActive }
139+ keepCache = { keepCache }
130140 />
131141 ) ) ;
132142 } ;
0 commit comments