Skip to content

Commit

Permalink
fix: #26126 use mergedData instead of pageData to decide if render bo…
Browse files Browse the repository at this point in the history
…ttom pagination (#26133)

Co-authored-by: Zhongxian Liang <zhongxian.liang@shopee.com>
  • Loading branch information
QoVoQ and Zhongxian Liang committed Aug 11, 2020
1 parent 1119c3d commit f650139
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components/table/Table.tsx
Expand Up @@ -495,7 +495,7 @@ function Table<RecordType extends object = any>(props: TableProps<RecordType>) {
internalRefs={internalRefs as any}
transformColumns={transformColumns}
/>
{pageData && pageData.length > 0 && bottomPaginationNode}
{mergedData && mergedData.length > 0 && bottomPaginationNode}
</Spin>
</div>
);
Expand Down
38 changes: 37 additions & 1 deletion components/table/__tests__/Table.pagination.test.js
Expand Up @@ -349,7 +349,7 @@ describe('Table.pagination', () => {
const dropdownWrapper = mount(wrapper.find('Trigger').instance().getComponent());
dropdownWrapper.find('.ant-select-item-option').at(2).simulate('click');

expect(onChange).toBeCalledTimes(1)
expect(onChange).toBeCalledTimes(1);
});

it('dynamic warning', () => {
Expand Down Expand Up @@ -377,4 +377,40 @@ describe('Table.pagination', () => {
'Warning: [antd: Table] `dataSource` length is less than `pagination.total` but large than `pagination.pageSize`. Please make sure your config correct data with async mode.',
);
});

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

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

0 comments on commit f650139

Please sign in to comment.