mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
fix: table should not show sorter when sorter is falsy (#20187)
fix #20096
This commit is contained in:
parent
d0d521fc63
commit
7b4123258b
@ -639,4 +639,34 @@ describe('Table.sorter', () => {
|
||||
);
|
||||
expect(wrapper.render()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
// https://github.com/ant-design/ant-design/issues/20096
|
||||
it('invalidate sorter should not display sorter button', () => {
|
||||
const wrapper = mount(
|
||||
<Table
|
||||
columns={[
|
||||
{
|
||||
title: 'Name',
|
||||
dataIndex: 'name',
|
||||
key: 'name',
|
||||
sorter: false,
|
||||
},
|
||||
{
|
||||
title: 'Age',
|
||||
dataIndex: 'age',
|
||||
key: 'age',
|
||||
sorter: null,
|
||||
},
|
||||
{
|
||||
title: 'Address',
|
||||
dataIndex: 'address',
|
||||
key: 'address',
|
||||
sorter: undefined,
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(wrapper.find('.ant-table-column-sorter-inner')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
|
@ -59,7 +59,7 @@ function collectSortStates<RecordType>(
|
||||
|
||||
if ('children' in column) {
|
||||
sortStates = [...sortStates, ...collectSortStates(column.children, init, columnPos)];
|
||||
} else if ('sorter' in column) {
|
||||
} else if (column.sorter) {
|
||||
if ('sortOrder' in column) {
|
||||
// Controlled
|
||||
sortStates.push({
|
||||
@ -95,7 +95,7 @@ function injectSorter<RecordType>(
|
||||
const columnPos = getColumnPos(index, pos);
|
||||
let newColumn: ColumnsType<RecordType>[number] = column;
|
||||
|
||||
if ('sorter' in newColumn) {
|
||||
if (newColumn.sorter) {
|
||||
const sortDirections: SortOrder[] = newColumn.sortDirections || defaultSortDirections;
|
||||
const columnKey = getColumnKey(newColumn, columnPos);
|
||||
const sorterState = sorterSates.find(({ key }) => key === columnKey);
|
||||
|
Loading…
Reference in New Issue
Block a user