From 18262297dafac0ec02708079c35639c505115c48 Mon Sep 17 00:00:00 2001 From: sdli <1669375803@qq.com> Date: Mon, 28 Jan 2019 22:43:03 +0800 Subject: [PATCH] fix table.pagination bug - when pageSize is larger than data source length --- components/table/Table.tsx | 6 +++++- components/table/__tests__/Table.pagination.test.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/components/table/Table.tsx b/components/table/Table.tsx index bd5e9ff782..d7422dadc1 100755 --- a/components/table/Table.tsx +++ b/components/table/Table.tsx @@ -1013,7 +1013,11 @@ export default class Table extends React.Component, 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; }); diff --git a/components/table/__tests__/Table.pagination.test.js b/components/table/__tests__/Table.pagination.test.js index 90c6c5327e..8d99e9e02d 100644 --- a/components/table/__tests__/Table.pagination.test.js +++ b/components/table/__tests__/Table.pagination.test.js @@ -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([]); + }); });