zoukankan      html  css  js  c++  java
  • 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]
        }
    

      

  • 相关阅读:
    AT2165 Median Pyramid Hard
    AT2160 へんなコンパス / Manhattan Compass
    bzoj2863:愤怒的元首
    bzoj5336:[TJOI2018]party
    [luoguP3768]简单的数学题
    bzoj1831:[AHOI2008]逆序对
    bzoj5492:[Hnoi2019]校园旅行
    HNOI2019游记
    HDU 1102 Constructing Roads(kruskal)
    HDU 1059 Dividing
  • 原文地址:https://www.cnblogs.com/tangxinwang/p/14047446.html
Copyright © 2011-2022 走看看