mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-27 20:49:53 +08:00
fix: Table with sort should reset to first page (#17020)
* sort reset pagination * add test case
This commit is contained in:
parent
8c417e6cbf
commit
e67270cd59
@ -414,6 +414,9 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
||||
if (!column.sorter) {
|
||||
return;
|
||||
}
|
||||
|
||||
const pagination = { ...this.state.pagination };
|
||||
|
||||
const sortDirections = column.sortDirections || (this.props.sortDirections as SortOrder[]);
|
||||
const { sortOrder, sortColumn } = this.state;
|
||||
// 只同时允许一列进行排序,否则会导致排序顺序的逻辑问题
|
||||
@ -428,7 +431,14 @@ export default class Table<T> extends React.Component<TableProps<T>, TableState<
|
||||
newSortOrder = sortDirections[0];
|
||||
}
|
||||
|
||||
if (this.props.pagination) {
|
||||
// Reset current prop
|
||||
pagination.current = 1;
|
||||
pagination.onChange!(pagination.current);
|
||||
}
|
||||
|
||||
const newState = {
|
||||
pagination,
|
||||
sortOrder: newSortOrder,
|
||||
sortColumn: newSortOrder ? column : null,
|
||||
};
|
||||
|
@ -587,4 +587,23 @@ describe('Table.sorter', () => {
|
||||
wrapper.find('.ant-table-column-sorters').simulate('click');
|
||||
expect(renderedNames(wrapper)).toEqual(['Jack', 'Lucy', 'Tom', 'Jerry']);
|
||||
});
|
||||
|
||||
it('pagination back', () => {
|
||||
const onPageChange = jest.fn();
|
||||
const onChange = jest.fn();
|
||||
|
||||
const wrapper = mount(
|
||||
createTable({
|
||||
pagination: {
|
||||
pageSize: 2,
|
||||
onChange: onPageChange,
|
||||
},
|
||||
onChange,
|
||||
}),
|
||||
);
|
||||
|
||||
wrapper.find('.ant-table-column-sorters').simulate('click');
|
||||
expect(onChange.mock.calls[0][0].current).toBe(1);
|
||||
expect(onPageChange.mock.calls[0][0]).toBe(1);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user