• Element-ui前端自定义排序


    1.在需要自定义排序的列上(el-table-column)加上sortable="cistom"

       2.在el-table上增加sort-change事件,监听列的排序

     

    //定义需要排序的列,这样可以省去多个if-else if
    const actions = new Map([
      ['votes', 'votes'],
      ['calcWeight', 'calcWeight'],
      ['addTransferFee', 'addTransferFee'],
      ['kiloCostBalance', 'kiloCostBalance'],
      ['dispatcherCalcWeight', 'dispatcherCalcWeight'],
      ['pafeiClosureFee', 'pafeiClosureFee'],
      ['kiloPafeiCostBalance', 'kiloPafeiCostBalance']
    ])
    

      

    使用一个proptype来存放需要排序的列

     // 自定义排序
        sortChange(column) {
          this.queryParams.pageIndex = 1
          const prop = actions.get(column.prop)
          if (prop) {
            this.proptype = prop
            if (column.order === 'ascending') {
              this.tableData.sort(this.ascSortFun)
            } else if (column.order === 'descending') {
              this.tableData.sort(this.desSortFun)
            }
          }
        },
        // 升序排列方法
        ascSortFun(a, b) {
          return a[this.proptype] - b[this.proptype]
        },
        // 降序排列方法
        desSortFun(a, b) {
          return b[this.proptype] - a[this.proptype]
        }
    

      

  • 相关阅读:
    对结对编程的测试
    用例
    结对编程 一
    个人项目总结与结对编程的开始
    7-6随便写写
    7-5个人日报
    7-4个人报告
    7.1-7.3个人日报
    6-30个人日报
    6-29个人日报
  • 原文地址:https://www.cnblogs.com/tangxinwang/p/14047446.html
Copyright © 2020-2023  润新知