mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 19:19:57 +08:00
fix: table multiple sorter (#24852)
* fix sort callback * add test case
This commit is contained in:
parent
af5ff52a27
commit
d6d3de8a1b
@ -272,7 +272,7 @@ describe('Table.sorter', () => {
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/pull/12264#discussion_r218053034
|
||||
it('should sort from begining state when toggle from different columns', () => {
|
||||
it('should sort from beginning state when toggle from different columns', () => {
|
||||
const columns = [
|
||||
{
|
||||
title: 'name',
|
||||
@ -790,4 +790,55 @@ describe('Table.sorter', () => {
|
||||
.hasClass('active'),
|
||||
).toBeTruthy();
|
||||
});
|
||||
|
||||
it('onChange with correct sorter for multiple', () => {
|
||||
const groupColumns = [
|
||||
{
|
||||
title: 'Math Score',
|
||||
dataIndex: 'math',
|
||||
sorter: { multiple: 1 },
|
||||
},
|
||||
{
|
||||
title: 'English Score',
|
||||
dataIndex: 'english',
|
||||
sorter: { multiple: 2 },
|
||||
},
|
||||
];
|
||||
|
||||
const groupData = [
|
||||
{
|
||||
key: '1',
|
||||
name: 'John Brown',
|
||||
chinese: 98,
|
||||
math: 60,
|
||||
english: 70,
|
||||
},
|
||||
];
|
||||
|
||||
const onChange = jest.fn();
|
||||
const wrapper = mount(<Table columns={groupColumns} data={groupData} onChange={onChange} />);
|
||||
|
||||
function clickToMatchExpect(index, sorter) {
|
||||
wrapper.find('.ant-table-column-sorters').at(index).simulate('click');
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith(
|
||||
expect.anything(),
|
||||
expect.anything(),
|
||||
expect.objectContaining(sorter),
|
||||
expect.anything(),
|
||||
);
|
||||
|
||||
onChange.mockReset();
|
||||
}
|
||||
|
||||
// First
|
||||
clickToMatchExpect(0, { field: 'math', order: 'ascend' });
|
||||
clickToMatchExpect(0, { field: 'math', order: 'descend' });
|
||||
clickToMatchExpect(0, { field: 'math', order: undefined });
|
||||
|
||||
// Last
|
||||
clickToMatchExpect(1, { field: 'english', order: 'ascend' });
|
||||
clickToMatchExpect(1, { field: 'english', order: 'descend' });
|
||||
clickToMatchExpect(1, { field: 'english', order: undefined });
|
||||
});
|
||||
});
|
||||
|
@ -231,7 +231,7 @@ function generateSorterInfo<RecordType>(
|
||||
// https://github.com/ant-design/ant-design/pull/19226
|
||||
if (list.length === 0 && sorterStates.length) {
|
||||
return {
|
||||
...stateToInfo(sorterStates[0]),
|
||||
...stateToInfo(sorterStates[sorterStates.length - 1]),
|
||||
column: undefined,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user