Reset pagination to first page #2288
-
Estou usando paginação com SSR e para obter os dados está funcionando corretamente. I am using pagination with SSR and to get the data is working correctly. Table Component
App Component
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
I've solved for this by setting a ref to After the // use this ref to keep track of updating internal table state
const tableStateUpdateRef = React.useRef(false);
React.useEffect(() => {
tableStateUpdateRef.current = true;
setFetchInfo({ sorted: sortBy, pageIndex, pageSize });
}, [setFetchInfo, sortBy, pageIndex, pageSize]);
// reset the page index to 0 when sorting changes
React.useEffect(() => {
gotoPage(0);
}, [gotoPage, sortBy]);
/* reset the page index to 0 when the table data updates due to something
other than internal table state changes
*/
React.useEffect(() => {
if (!tableStateUpdateRef.current) {
gotoPage(0);
}
}, [data, gotoPage]);
// clear our ref when the data is loaded, after we perform any side effects
React.useEffect(() => {
tableStateUpdateRef.current = false;
}, [data]); |
Beta Was this translation helpful? Give feedback.
-
Isn't this result in duplicate fetch requests? When you:
At least for me it does work like that.
|
Beta Was this translation helpful? Give feedback.
-
I solved for this these two lines of code.
|
Beta Was this translation helpful? Give feedback.
I've solved for this by setting a ref to
true
to track if state is being updated from "internal table state" vs external state.setFetchInfo
is a state updater for table state params that results in a fetch in the parent component.After the
useTable
hook: