Ant Design table 排序 ,点击头部只有升序和降序


state = {
sortedInfo: {
columnKey:'proportion',
order:'descend'
},
saveSortedInfo:null
}

每列
const columns = [
{
title: '名称',
dataIndex: 'name',
key: 'name',
className:'t_center',
width:'120px'
},
{
title: '占比',
dataIndex: 'proportion',
key: 'proportion',
className:'t_center',
sorter: (a, b) => a.proportion - b.proportion,
defaultSortOrder:'descend',
sortDirections: [ 'descend','ascend'],
sortOrder: sortedInfo.columnKey === 'proportion' && sortedInfo.order,

},
  {....},{...}
]

//变化事件
function has_value(data){
return Object.keys(data).length>0
}
handleChange = (pagination, filters, sorter) => {
if(has_value(sorter)){ //判断sorter 是否为null ,我用的是Object.keys(obj).length
this.setState({
sortedInfo: sorter,
saveSortedInfo: sorter //保存此次点击的对象
});
}else{
this.setState({
sortedInfo:{
order:this.state.saveSortedInfo.order=='ascend'?'descend':'ascend',
columnKey:this.state.saveSortedInfo.columnKey
}
})
}



}



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM