Skip to content

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

Closed
hamidvirani wants to merge 1 commit into
TanStack:mainfrom
hamidvirani:feature/rectify-pageindex
Closed

Fix an issue where pageIndex becomes invalid when data is changed (removed) and autoResetPageIndex is false.#5031
hamidvirani wants to merge 1 commit into
TanStack:mainfrom
hamidvirani:feature/rectify-pageindex

Conversation

@hamidvirani

Copy link
Copy Markdown

This fixes issue #4994

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

@hamidvirani
hamidvirani force-pushed the feature/rectify-pageindex branch from 302bbe4 to bb83e52 Compare August 20, 2023 14:18
@KevinVandy

Copy link
Copy Markdown
Member

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

@hamidvirani
hamidvirani force-pushed the feature/rectify-pageindex branch from bb83e52 to afdd446 Compare October 27, 2023 00:51
@hamidvirani

Copy link
Copy Markdown
Author

Hi,

Do you think this PR can be merged?

@p-viral

p-viral commented Jan 11, 2024

Copy link
Copy Markdown

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.

@KevinVandy

Copy link
Copy Markdown
Member

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.

@hamidvirani
hamidvirani force-pushed the feature/rectify-pageindex branch from afdd446 to d5066e9 Compare March 19, 2024 23:55
@hamidvirani

Copy link
Copy Markdown
Author

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

@Naofal-Helal

Copy link
Copy Markdown

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]);

@KevinVandy
KevinVandy deleted the branch TanStack:main August 4, 2026 04:41
@KevinVandy KevinVandy closed this Aug 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants