diff --git a/components/table/__tests__/Table.pagination.test.js b/components/table/__tests__/Table.pagination.test.js index 68e2f9b435..b91ec9c8ed 100644 --- a/components/table/__tests__/Table.pagination.test.js +++ b/components/table/__tests__/Table.pagination.test.js @@ -315,4 +315,9 @@ describe('Table.pagination', () => { wrapper.find('.ant-pagination-item-2').hasClass('ant-pagination-item-active'), ).toBeTruthy(); }); + + it('pagination should ignore invalidate total', () => { + const wrapper = mount(createTable({ pagination: { total: null } })); + expect(wrapper.find('.ant-pagination-item-1').length).toBeTruthy(); + }); }); diff --git a/components/table/hooks/usePagination.ts b/components/table/hooks/usePagination.ts index 11b9d1e7d0..d55f3aa6d5 100644 --- a/components/table/hooks/usePagination.ts +++ b/components/table/hooks/usePagination.ts @@ -30,7 +30,8 @@ export default function usePagination( pagination: TablePaginationConfig | false | undefined, onChange: (current: number, pageSize: number) => void, ): [TablePaginationConfig, () => void] { - const paginationObj = pagination && typeof pagination === 'object' ? pagination : {}; + const { total: paginationTotal = 0, ...paginationObj } = + pagination && typeof pagination === 'object' ? pagination : {}; const [innerPagination, setInnerPagination] = useState(() => { return { @@ -43,11 +44,11 @@ export default function usePagination( // ============ Basic Pagination Config ============ const mergedPagination = { ...innerPagination, - total, ...paginationObj, + total: paginationTotal > 0 ? paginationTotal : total, }; - if (!paginationObj.total) { + if (!paginationTotal) { // Reset `current` if data length changed. Only reset when paginationObj do not have total const maxPage = Math.ceil(total / mergedPagination.pageSize!); if (maxPage < mergedPagination.current!) {