//按数字大小排 sorter: (a, b) => a.type - b.type, //按length排序 sorter: (a, b) => a.name.length - b.name.length,
//根据汉字拼音来排序。
sorter: (a, b) => a['dataIndex'].localeCompare(b['dataIndex']) 升序
sorter: (a, b) => b['dataIndex'].localeCompare(a['dataIndex']) 降序
{ align: 'center', title: '地区', dataIndex: 'region', with: '25%', sorter: (a, b) => a['region'].localeCompare(b['region']) }
结果:
补充
const columns = [
{
title: '汉字',
dataIndex: 'name',
sorter:(a,b) => a.name.localeCompare(b.name)
},
{
title: '数字',
dataIndex: 'amount',
sorter: (a, b) => Number(a.amount) - Number(b.amount),
},
{
title: '字符串',
dataIndex: 'value',
sorter: (a, b) => a.value.localeCompare(b.value)
},
{
title: '字符串',
dataIndex: 'pbom',
sorter: (a, b) => {
for (let i = 0; i < a.pbom.length; i++) {
if (b.pbom[i] !== undefined) {
if (a.pbom.charCodeAt(i) > b.pbom.charCodeAt(i)) {
return 1;
} else {
return -1;
}
} else {
return -1;
}
}
}
}
];
补充:日期排序
sorter: (a, b) => {
const aTime = new Date(a.nowTime).getTime()
const bTime = new Date(b.nowTime).getTime()
return aTime - bTime
}