Skip to content
Source
Sign inSign up
TanStack/table

Fix an issue where pageIndex becomes invalid when data is changed (removed) and autoResetPageIndex is false. #5031

Closedhamidvirani(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/5031/headopened

This fixes issue #4994

The pageIndex now gets set to correct value, if invalid, when autoResetPageIndex is false and data changes

    1. I like this! I have to get around it with an useEffect in my tanstack table code bases like this:

      https://github.com/KevinVandy/mantine-react-table/blob/433b24f761e10e4268039763479e8b415286334f/packages/mantine-react-table/src/hooks/useMRT_Effects.ts#L50

      Will look into merging this fix

    2. Hi,

      Do you think this PR can be merged?

    3. Any news on when this will be merged?

      I am hoping to get this working to release app to production. This is a blocker if pagination does not reset when the last row is deleted in the last page and the table does not reset to the previous page.

      Please help.

    4. Any news on when this will be merged?

      I am hoping to get this working to release app to production. This is a blocker if pagination does not reset when the last row is deleted in the last page and the table does not reset to the previous page.

      Please help.

      You can always just do this with your own code. Any fix here would just be a quality of life update.

    5. @KevinVandy I have resolved the conflicts if we want to merge this PR

    6. I am hoping to get this working to release app to production. This is a blocker if pagination does not reset when the last row is deleted in the last page and the table does not reset to the previous page.

      If anyone else is facing this issue and this is not yet merged, here is the workaround for React:

        useEffect(() => {
          const currentPageIndex = table.getState().pagination.pageIndex;
          const lastPageIndex = table.getPageCount() - 1;
          if (currentPageIndex > lastPageIndex) {
            table.setPageIndex(lastPageIndex);
          }
        }, [data.length]);
    7. KevinVandy closed this

Sign in to join this conversation.