mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 20:49:14 +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'),
|
wrapper.find('.ant-pagination-item-2').hasClass('ant-pagination-item-active'),
|
||||||
).toBeTruthy();
|
).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,
|
pagination: TablePaginationConfig | false | undefined,
|
||||||
onChange: (current: number, pageSize: number) => void,
|
onChange: (current: number, pageSize: number) => void,
|
||||||
): [TablePaginationConfig, () => 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>(() => {
|
const [innerPagination, setInnerPagination] = useState<TablePaginationConfig>(() => {
|
||||||
return {
|
return {
|
||||||
@ -43,11 +44,11 @@ export default function usePagination(
|
|||||||
// ============ Basic Pagination Config ============
|
// ============ Basic Pagination Config ============
|
||||||
const mergedPagination = {
|
const mergedPagination = {
|
||||||
...innerPagination,
|
...innerPagination,
|
||||||
total,
|
|
||||||
...paginationObj,
|
...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
|
// Reset `current` if data length changed. Only reset when paginationObj do not have total
|
||||||
const maxPage = Math.ceil(total / mergedPagination.pageSize!);
|
const maxPage = Math.ceil(total / mergedPagination.pageSize!);
|
||||||
if (maxPage < mergedPagination.current!) {
|
if (maxPage < mergedPagination.current!) {
|
||||||
|
Loading…
Reference in New Issue
Block a user