Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-Table Hooks - pageIndex reset when changing page

I am implementing a react-table component containing server-side pagination and I need sorting on the columns as well.

However I am observing strange behaviors. When I am using only pagination and click on next page the pageIndex is getting incremented.

However when I add sorting hooks then then pagination in not working. The pageIndex is getting back to 1 automatically and I am not able to figure it why.

Can any one help me out. Below is sandbox link https://codesandbox.io/s/eager-breeze-9cw0r.

like image 910
Geetanshu Gulati Avatar asked Feb 13 '26 16:02

Geetanshu Gulati


1 Answers

When making changes to the external data you want to disable automatic resets to the state of the table (see https://github.com/TanStack/table/blob/main/docs/faq.md for more info). So in your case changing the page modifies the data you're passing to the table, which leads to the state of the table being reset.

In order to stop this you need to set autoResetPage to false. Eg:

useTable<FormattedRowData<T>>(
    {
      autoResetPage: false
    });

I made the change to your sandbox and this resolved the issue.

like image 50
Castrohenge Avatar answered Feb 16 '26 10:02

Castrohenge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!