Bugfix/table pageindex sync with total pages (#1263)

* Update table page data when page index is updated

* Pass pageIndex from useTable hook as lastActivePageIndex for pagination

* Goto last page in table whenever page count is less than current page index
This commit is contained in:
Sherfin Shamsudeen 2021-10-25 14:00:52 +05:30 committed by GitHub
parent 939303f3ad
commit ef9951b255
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View file

@ -21,7 +21,10 @@ export const Pagination = function Pagination({
setPageCount(lastActivePageIndex);
} else if (serverSide || lastActivePageIndex === 0) {
setPageIndex(1);
} else {
gotoPage(lastActivePageIndex + 1);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [serverSide, lastActivePageIndex]);
function gotoPage(page) {

View file

@ -756,6 +756,10 @@ export function Table({
}
}, [state.columnResizing.isResizingColumn]);
useEffect(() => {
if (pageCount <= pageIndex) gotoPage(pageCount - 1);
}, [pageCount]);
return (
<div
data-disabled={parsedDisabledState}
@ -891,7 +895,7 @@ export function Table({
<div className="col">
{(clientSidePagination || serverSidePagination) && (
<Pagination
lastActivePageIndex={currentState.components[component.name]?.pageIndex ?? 1}
lastActivePageIndex={pageIndex}
serverSide={serverSidePagination}
autoGotoPage={gotoPage}
autoCanNextPage={canNextPage}