1、在页面el-table-column添加sortable :sort-orders="['ascending', 'descending']"
如果需要后端排序,需将sortable设置为custom,同时在 Table 上监听sort-change事件,在事件回调中可以获取当前排序的字段名和排序顺序,从而向接口请求排序后的表格数据。
<el-table :data="tableData" class="table"
max-height="680"
size="small"
tooltip-effect="dark"
style="width: 100%;cursor: pointer;"
@sort-change="getSortChange"
:header-cell-style="tableHeaderColor">
<el-table-column type="selection" width="55" align="center"></el-table-column>
<el-table-column prop="orderId" label="编号" width="150" >
</el-table-column>
<el-table-column prop="applicationName" label="应用名称" >
</el-table-column>
<el-table-column prop="code" label="订单编码" sortable :sort-orders="['ascending', 'descending']">
</el-table-column>
<el-table-column prop="isAbnormal" label="状态" >
<template slot-scope="scope">
<span v-if="scope.row.isAbnormal == 'enable'">正常</span>
<span v-if="scope.row.isAbnormal == 'disable'">异常</span>
</template>
</el-table-column>
</el-table>
2、定义methods监听sort-change事件
//排序getSortChange
getSortChange(column){
if (column.order === 'descending') {
this.query.Sort = column.prop;
this.query.isAsc = 'desc'
} else {
this.query.Sort = column.prop;
this.query.isAsc = 'asc'
}
this.getData()
},
网友评论