vue代码
1.el-table 标签上加 @sort-change="sortChange"
2.el-table-column 标签上加 prop=“block” 和 sortable=“custom” 标记
<el-table
v-loading="listLoading"
:data="list"
border
style="margin-top: 10px;"
@sort-change="sortChange"
>
<el-table-column
type="index"
width="70"
:label="$t('table.id')"
align="center"
>
</el-table-column>
<el-table-column
:label="$t('data.block')"
align="center"
sortable="custom"
prop="block"
>
<template slot-scope="{ row }">
{{ row.block }}
</template>
</el-table-column>
</el-table>
<script>
private listQuery = {
sort: "",
order: ""
}
private sortChange(data: any) {
const { prop, order } = data;
this.listQuery.order = prop;
if (order == "ascending") {
this.listQuery.sort = "ASC";
} else if (order == "descending") {
this.listQuery.sort = "DESC";
}
this.getList();
}
</script>
xml
<select id="read" resultMap="beans">
select id,
block,
floor
from property
where 1=1
<if test="order != null and order != ''">
order by ${order} ${sort}
</if>
</select>