Skip to content

Commit

Permalink
fix: Table topPaginationNode display logic should same with bottomPag…
Browse files Browse the repository at this point in the history
…inationNode (ant-design#26143)

* fix: Tree bottomPaginationNode display logic should same with bottomPaginationNode

* update: test
  • Loading branch information
zhangchen915 committed Aug 28, 2020
1 parent 77cbf72 commit c47bfb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
4 changes: 2 additions & 2 deletions components/table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {

let topPaginationNode: React.ReactNode;
let bottomPaginationNode: React.ReactNode;
if (pagination !== false) {
if (pagination !== false && mergedPagination?.total) {
let paginationSize: TablePaginationConfig['size'];
if (mergedPagination.size) {
paginationSize = mergedPagination.size;
Expand Down Expand Up @@ -495,7 +495,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
internalRefs={internalRefs as any}
transformColumns={transformColumns}
/>
{mergedData && mergedData.length > 0 && bottomPaginationNode}
{bottomPaginationNode}
</Spin>
</div>
);
Expand Down
47 changes: 16 additions & 31 deletions components/table/__tests__/Table.pagination.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,39 +378,24 @@ describe('Table.pagination', () => {
);
});

it('should render pagination after last item on last page being removed with async mode', () => {
const lastPageNum = data.length;
it('should render pagination after last item on last page being removed', () => {
const total = data.length;
const paginationProp = {
pageSize: 1,
total,
current: total,
position: ['topLeft', 'bottomLeft'],
};
const wrapper = mount(
createTable({ pagination: { pageSize: 1, total: data.length, current: lastPageNum } }),
createTable({
pagination: paginationProp,
}),
);

const newCol = [
{
title: 'Name',
dataIndex: 'name',
},
{
title: 'Action',
dataIndex: 'name',
render(_, record) {
const deleteRow = () => {
const newData = data.filter(d => d.key !== record.key);
wrapper.setProps({
dataSource: newData,
pagination: { pageSize: 1, total: newData.length, current: lastPageNum },
});
};
return (
<span className="btn-delete" onClick={deleteRow}>
Delete
</span>
);
},
},
];

wrapper.setProps({ columns: newCol });
wrapper.find('.btn-delete').simulate('click');
expect(wrapper.find('.ant-pagination')).toHaveLength(1);
wrapper.setProps({
dataSource: data.slice(total - 1),
pagination: { ...paginationProp, total: total - 1 },
});
expect(wrapper.find('.ant-pagination')).toHaveLength(2);
});
});

0 comments on commit c47bfb0

Please sign in to comment.