el-table實現後臺全量排序

1.第一個關鍵點是在需要在要排列的列上加上sortable: ‘custom’,

  <el-table-column
       prop="date"
       label="打卡時間"
       sortable="custom"
       width="180">

2.在table上添加事件,@sort-change="topTableSort"
如果有需要添加一個默認排序方式,:default-sort = “{prop: ‘opdt’, order: ‘ascending’}”
ascending 排序的上面箭頭會高亮
descending 排序的下面箭頭會高亮

   <el-table  size="medium"
	    :data="tableDataTop"
	    stripe
	    @sort-change="topTableSort"
	    :default-sort = "{prop: 'opdt', order: 'ascending'}"
	    style="width: 100%">

3.規定@sort-change對應方法topTableSort傳遞參數,order指的是你點擊的是升序還是降序,
,如果升序傳遞什麼參數,如果是降序傳遞什麼參數,具體的參數是需要和後臺商量訂的。

 topTableSort({ column, prop, order }) {
	if (column) {
       if (column.label == "券發放量" && order == "descending") {
          this.orderBy = 1;
          this.orderType = 1;
        }
        if (column.label == "券發放量" && order == "ascending") {
          this.orderBy = 1;
          this.orderType = 0;
        }
        if (column.label == "有效客戶數" && order == "descending") {
          this.orderBy = 2;
          this.orderType = 1;
        }
        if (column.label == "有效客戶數" && order == "ascending") {
          this.orderBy = 2;
          this.orderType = 0;
        }
        this.getTableData();
	}
}

其實前面的兩步在elementui上都能找得到,第三步可能就要仔細看了,很多人就是不知道,如何判斷什麼時候應該傳什麼參數,希望看了這篇文章對你有幫助。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章