背景:官方和网上的例子都很简单,实际项目开发中比较的一般都是对象数组,且属性值不一定全为数值,有可能为字符串,比如某个数据没有值,默认显示字符串:"--"
需求:降序或者升序无数值的在最后面显示
开发步骤:
(1)HTML:<a-table @change='compare' :columns='columns'>
(2)methods:
compare(pagination, filters, sorter, { currentDataSource }) { this.order = sorter.order }, (3)data: order:"", columns :[ { title: "序号", dataIndex: "id", key: "id", }, { title: "站点信息", dataIndex: "station", key: "station", }, { dataIndex: "", slots: { title: "current_data_type_name" }, //标题,current_data_type_name为变量 scopedSlots: { customRender: "name" }, //用于每行数据显示 sorter: (a, b) => { let an = isNaN(parseFloat(a[this.current_data_type])) ? (this.order === 'descend' ? -99999999: 9999999): a[this.current_data_type] let bn = isNaN(parseFloat(b[this.current_data_type])) ? (this.order === 'descend' ? -99999999: 9999999): b[this.current_data_type] return an - bn }, }, ];//this.current_data_type标识对象的key