fix table.pagination bug - when pageSize is larger than data source length

This commit is contained in:
sdli 2019-01-28 22:43:03 +08:00
parent 6240871c6b
commit 18262297da
2 changed files with 15 additions and 1 deletions

View File

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

View File

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