From e73199a04d7a958d45f6ea945ed2ae84460fd69d Mon Sep 17 00:00:00 2001 From: Vivek Kumar Bansal <5930351+vkbansal@users.noreply.github.com> Date: Wed, 1 Apr 2020 22:04:20 +0530 Subject: [PATCH] fix: manualPagination does not work with pageCount -1 (#2024) * fix: manualPagination does not work with pageCount -1 * fix: manualPagination does not work with pageCount -1 --- src/plugin-hooks/usePagination.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/plugin-hooks/usePagination.js b/src/plugin-hooks/usePagination.js index 735f108..0ff1ac5 100755 --- a/src/plugin-hooks/usePagination.js +++ b/src/plugin-hooks/usePagination.js @@ -43,12 +43,18 @@ function reducer(state, action, previousState, instance) { } if (action.type === actions.gotoPage) { - const { pageCount } = instance + const { pageCount, page, rows } = instance const newPageIndex = functionalUpdate(action.pageIndex, state.pageIndex) + const cannnotPreviousPage = newPageIndex < 0 + const cannotNextPage = + pageCount === -1 + ? page.length < state.pageSize + : newPageIndex > pageCount - 1 - if (newPageIndex < 0 || newPageIndex > pageCount - 1) { + if (cannnotPreviousPage || cannotNextPage) { return state } + return { ...state, pageIndex: newPageIndex, @@ -153,7 +159,8 @@ function useInstance(instance) { ]) const canPreviousPage = pageIndex > 0 - const canNextPage = pageCount === -1 || pageIndex < pageCount - 1 + const canNextPage = + pageCount === -1 ? page.length >= pageSize : pageIndex < pageCount - 1 const gotoPage = React.useCallback( pageIndex => {