mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-18 22:36:31 +08:00
fix table.pagination bug - when pageSize is larger than data source length
This commit is contained in:
parent
6240871c6b
commit
18262297da
@ -1013,7 +1013,11 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
||||
// ---
|
||||
// 当数据量少于等于每页数量时,直接设置数据
|
||||
// 否则进行读取分页数据
|
||||
if (data.length > pageSize || pageSize === Number.MAX_VALUE) {
|
||||
if (
|
||||
data.length > pageSize ||
|
||||
pageSize === Number.MAX_VALUE ||
|
||||
current * pageSize > data.length
|
||||
) {
|
||||
data = data.filter((_, i) => {
|
||||
return i >= (current - 1) * pageSize && i < current * pageSize;
|
||||
});
|
||||
|
@ -176,4 +176,14 @@ describe('Table.pagination', () => {
|
||||
.find('.ant-pagination'),
|
||||
).toHaveLength(1);
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/14557
|
||||
it('Show correct page data when pagination data length is less than pageSize.', () => {
|
||||
const wrapper = mount(
|
||||
createTable({ pagination: { pageSize: 10, total: 100 }, dataSource: data }),
|
||||
);
|
||||
expect(renderedNames(wrapper)[0]).toEqual('Jack');
|
||||
wrapper.find('.ant-pagination-item-2').simulate('click');
|
||||
expect(renderedNames(wrapper)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user