elementUI的组件自定义排序

2021-03-11  本文已影响0人  剑圣_盖小聂

业务场景:表格有”发布时间“一列,发布时间可以点击上下箭头排序(和后台交互排序所有数据,非当前表格里的几条)。
html:

<el-table :data="tableData" style="width: 100%" @sort-change="sortChange">
    <!--   sortable="custom"很重要   -->
    <el-table-column prop="publishTime" sortable="custom" label="发布时间" > </el-table-column>
</el-table>

js:

sortChange(column) {
            //打印可以分别得到上下箭头的数据
            console.log(column);
            if (column.order == "ascending") {
                this.orderBy = "+";//根据自己的业务需求来
            } else if (column.order == "descending") {
                this.orderBy = "-";
            } else {
                this.orderBy = "";
            }
            //有多列排序时会用到
            // if (column.prop == "publishTime") {
            //     this.key = "publish_time ";
            // }  else if (column.prop == "updateTime") {
            //     this.key = "update_time";
            // } else {
            //     this.key = "";
            // }
            this.currentPage = 1;
            this.searchData();//查询列表方法
        },
上一篇 下一篇

猜你喜欢

热点阅读