TanStack / table

🤖 Headless UI for building powerful tables & datagrids for TS/JS - React-Table, Vue-Table, Solid-Table, Svelte-Table
https://tanstack.com/table
MIT License
24.61k stars 3.04k forks source link

autoResetPageIndex not resetting properly #5459

Closed marcellino-ornelas closed 3 months ago

marcellino-ornelas commented 3 months ago

TanStack Table version

8.15.0

Framework/Library version

^18.2.0

Describe the bug

Hello, Im running into a issue with the autoResetPageIndex showing/processing the incorrect page Index when using client side pagination and changing the rows per page.

Steps to reproduce

  1. Click next page 2 times so you see Page 3 of 10,000
  2. Click the rows per page option
  3. Select option show 20

You will now see the incorrect number Page 2 of 5,000

Expected behavior

  1. Click next page 2 times so you see Page 3 of 10,000
  2. Click the rows per page option
  3. Select option show 20

You should now see Page 1 of 5,000

How often does this bug happen?

Every time

Platform

TypeScript version

5.1.6

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/tanstack-table-csasqf?file=src%2Fmain.tsx

Screenshots or Videos (Optional)

https://github.com/TanStack/query/assets/35247622/969eb333-4b99-499a-85b9-4b9415224ca9

Do you intend to try to help solve this bug with your own PR?

No, because I do not know how

Terms & Code of Conduct

marcellino-ornelas commented 3 months ago

Current work around

const handleChangeRowsPerPage = useCallback(
        (event: React.ChangeEvent<HTMLInputElement>): void => {
            table.setPageIndex(0);
            table.setPageSize(Number(event.target.value));
        },
        [table],
    );
KevinVandy commented 3 months ago

In my initial testing, it appears to me that the table is going back to the correct initial page upon a sort, but not upon a pageSize change.

This is the expected behavior. Only events such as sorting, filtering, or grouping should trigger an auto-reset. Changing the page size should not trigger this. Your workaround is the solution if you want that behavior though.

There are edge case scenarios that are similar to this, but not exactly the same that are being considered to be fixed. https://github.com/TanStack/table/pull/5031