fix: Table with invalidate pagination totol should ignore (#20532)

This commit is contained in:
二货机器人 2019-12-30 15:35:53 +08:00 committed by GitHub
parent 5f7ca16ed5
commit f2fdf490de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -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();
});
});

View File

@ -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<TablePaginationConfig>(() => {
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!) {