GroupedRowModel is incompatible with Pagination
TanStack Table version
v8.21.3
Framework/Library version
React v18.2.0
Describe the bug and the steps to reproduce it
When the table is initialized with a pagination state, and the getGroupedRowModel is set, the pageIndex is immediately reset to 0.
Here is a demo https://codesandbox.io/p/devbox/github/tanstack/table/tree/main/examples/react/pagination?embed=1&theme=light
It is taken directly from the pagination example, with 2 changes:
- Updating the initial pageIndex to (for example) 5
- Add
getGroupedRowModel: getGroupedRowModel(),to the table options
(Note: this also occurs when a grouping state is passed, but having a grouping state is not required to see the issue)
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
https://codesandbox.io/p/devbox/github/tanstack/table/tree/main/examples/react/pagination?embed=1&theme=light
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
Yes, I am also opening a PR that solves the problem along side this issue
Terms & Code of Conduct
- [x] I agree to follow this project's Code of Conduct
- [x] I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
As far as I can tell the issue is that the _autoResetPageIndex called during the init of getGroupedRowModel is wrapped in a _queue.
As a result the actual call to _autoResetPageIndex occurs after registered has been set to true by other models.