table表格的数据需要根据某列,进行升序/降序的操作
sortable
el-table列属性,控制对应列是否可以排序,如果设置’custom’,则代表用户希望远程排序,需要监听table的sort-change事件
<template>
<el-table
:data="tableData"
@sort-change="sortChange"
:default-sort="{ prop: 'age', order: 'descending' }"
border
ref="table"
style="width: 100%"
height="252px"
>
<el-table-column prop="index" label="排名" align="center" show-overflow-tooltip width="50"> </el-table-column>
<el-table-column prop="name" label="名称" align="center" show-overflow-tooltip> </el-table-column>
<el-table-column prop="serialNumber" label="编号" align="center" show-overflow-tooltip> </el-table-column>
<el-table-column prop="age" label="年龄" align="center" sortable="custom" show-overflow-tooltip> </el-table-column>
</el-table>
</template>
<script>
export default {
...
methods:{
//升序、降序处理
sortChange ({ column, prop, order }) {
if (order) {
this.orderName = prop;
this.orderMethod = order;
} else {
this.orderName = 'age';
this.orderMethod = 'ascending';
this.$refs.table.sort('age', 'ascending');
}
...
},
}
}
</script>