Ant Design中的表格可以实现基于多列的排序功能。可以通过在columns数组中设置sorter属性,为每一列指定排序规则并添加多个规则来实现多列排序。同时,还可以设置defaultSortOrder属性来设置默认排序方式。示例代码:
const columns = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
sorter: (a, b) => a.name.localeCompare(b.name),
// 多个排序规则
sortDirections: ['descend', 'ascend'],
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
sorter: (a, b) => a.age - b.age,
sortDirections: ['descend', 'ascend'],
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
sorter: (a, b) => a.address.localeCompare(b.address),
sortDirections: ['descend', 'ascend'],
},
];