From d5066e9d82eedfafbf4b1e0f465a37e8843e25a6 Mon Sep 17 00:00:00 2001 From: Hamid Virani Date: Sat, 19 Aug 2023 11:16:26 -0400 Subject: [PATCH] Fix an issue where pageIndex becomes invalid when data is changed (removed) and autoResetPageIndex is false. --- .../table-core/src/features/RowPagination.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/table-core/src/features/RowPagination.ts b/packages/table-core/src/features/RowPagination.ts index 836470673b..2e4a324e7f 100644 --- a/packages/table-core/src/features/RowPagination.ts +++ b/packages/table-core/src/features/RowPagination.ts @@ -224,14 +224,24 @@ export const RowPagination: TableFeature = { } if ( - table.options.autoResetAll ?? - table.options.autoResetPageIndex ?? + table.getState().pagination && !table.options.manualPagination ) { if (queued) return queued = true table._queue(() => { - table.resetPageIndex() + if ( + table.options.autoResetAll ?? + table.options.autoResetPageIndex + ) { + table.resetPageIndex() + } else { + const currentPageIndex = table.getState().pagination.pageIndex + const lastPageIndex = table.getPageCount() - 1 + if (currentPageIndex > lastPageIndex) { + table.setPageIndex(lastPageIndex) + } + } queued = false }) }