简体   繁体   English

React-Table Hooks - pageIndex 在更改页面时重置

[英]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.我正在实现一个包含服务器端分页的 react-table 组件,我也需要对列进行排序。

However I am observing strange behaviors.但是,我正在观察奇怪的行为。 When I am using only pagination and click on next page the pageIndex is getting incremented.当我只使用分页并单击下一页时, pageIndex会增加。

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. pageIndex自动恢复为 1,我无法弄清楚原因。

Can any one help me out.谁能帮我吗。 Below is sandbox link https://codesandbox.io/s/eager-breeze-9cw0r .下面是沙箱链接https://codesandbox.io/s/eager-breeze-9cw0r

When making changes to the external data you want to disable automatic resets to the state of the table (see https://react-table.js.org/faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes for more info).更改外部数据时,您希望禁用自动重置表状态(请参阅https://react-table.js.org/faq#how-do-i-stop-my-table-state-from -automatically-resetting-when-my-data-changes以获取更多信息)。 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 .为了阻止这种情况,您需要将autoResetPage设置为false Eg:例如:

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

I made the change to your sandbox and this resolved the issue.我对您的沙箱进行了更改,这解决了问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM