mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 04:30:06 +08:00
fix: Table with invalidate pagination totol should ignore (#20532)
This commit is contained in:
parent
5f7ca16ed5
commit
f2fdf490de
@ -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();
|
||||
});
|
||||
});
|
||||
|
@ -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!) {
|
||||
|
Loading…
Reference in New Issue
Block a user