Table remote sorting:
The attribute to be sorted is added: sortable='custom'
table added: @sort-change='sortChange'
Page bug:
el-table(
:data='dataList'
border
@sort-change='sortChange'
)
el-table-column(prop='ruleId' label='配置编号' align='center' sortable='custom' width='120')
...
el-table-column(prop='lastUpdateTime' label='最后修改时间' align='center' width='140' sortable='custom')
js:
// 监听表头点击获取排序参数
sortChange(column) {
const { order = '', prop = '' } = column;
this.loadData(order, prop);
},
Agree with the backend to request data function interface to add parameters:
loadData(order = 'descending', prop = 'lastUpdateTime') { // 加载数据
const params = {
...
'orderBy.property': prop,
'orderBy.direction': order === 'ascending' ? 'asc' : 'desc',
};
...
},
When there are two props to be sorted in the table header, specify the default sorting method:
Add attribute to html:: default-sort='defaultSort'
el-table(
:data='dataList'
border
@sort-change='sortChange'
:default-sort='defaultSort'
)
js:
defaultSort: {
prop: 'lastUpdateTime',
order: 'descending',
},
When clicking another prop to sort and then click the query button, how can I manually intervene to change the selected state of the sort to the default sorted prop:
table setting ref:
el-table(
:data='dataList'
border
@sort-change='sortChange'
:default-sort='defaultSort'
ref="table"
)
js:
search() { // 搜索数据
this.loadData();
this.$refs.table.sort('lastUpdateTime', 'descending'); // 手动修改table排序按钮选中状态
},