el-table 的sort-change

 

 

      @sort-change="changeTableSort"

 

 changeTableSort (column) {
      const fieldName = column.prop;
      const sortingType = column.order;
      let tableData = [...this.tableDataCopy];
      let sumData = {};
      tableData.map((item, index) => {
        if (item.problemTypeName === null) {
          sumData = item;
        }
      })
      if (sortingType != null) {
        if (sortingType == "ascending") {
          // 升序
          tableData = tableData.sort((a, b) => b[fieldName] - a[fieldName]);
        } else if (sortingType == "descending") {
          // 降序
          tableData = tableData.sort((a, b) => a[fieldName] - b[fieldName]);
        }
        tableData.forEach((item, index) => {
          if (item.problemTypeName === null) {
            tableData.splice(index, 1);
          }
        })
        tableData.unshift(sumData)
        this.tableData = tableData;
      }
      else {
        this.tableData = this.tableDataCopy;

      }
    },

 

posted @ 2024-05-29 16:37  ThisCall  阅读(440)  评论(0编辑  收藏  举报