element多列排序

这篇博客介绍了如何在前端使用El-Table组件实现表格数据的排序功能,包括单列排序和多级排序。通过监听sort-change事件和自定义表头样式,动态更新排序状态并调用后端接口获取排序后的数据。同时,文章还涉及了重置排序状态的逻辑处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 <div class="table">
      <el-table
        :data="tableData"
        borderstyle="width: 100%"
        border
        stripe
        @sort-change="sortChange"
        ref="table"
        :height="tableHeight"
        :header-cell-style="handleTheadStyle"
      >
<el-table-column label="Ledger Amt" prop="amountLedger" min-width="100" align="center" sortable="amountLedger">
          <template slot-scope="scope">
            <span>{{scope.row.amountLedger | thousands}}</span>
          </template>
</el-table-column>
  props: {
    mutilSort: {
        default: true
    },
  },
  data() {
    return {
      activeThead: {} //保存所选择的表头
    }
  }
 reset() {
      this.searchForm = {};
      this.sortList = [];
      this.$refs.table.clearSort();
      for(let key in this.activeThead){
        if(this.activeThead[key]){
          this.activeThead[key].column.order = '';
          this.activeThead[key].order = '';
          this.activeThead
        }
      }
      this.getTableData();
    },
    sortChange(column) {
      let sidx = column.prop;
      let order = column.order;
      if(sidx == 'valueDate'){
        sidx = 'valueDatetime'
      }
      if(column.order == 'descending'){
        order = 'desc'
      }else if(column.order == 'ascending'){
        order = 'asc'
      }else {
        order = null
      }
      let sort = {[sidx]:order}
      this.sortList.push(sort)
      this.getTableData();
      if (!this.mutilSort) return;
      if (column.order) {
          this.activeThead[column.prop] = {
            column,
            order:column.order
          }
      } else if (!column.order) {
          this.activeThead[column.prop] = "";
      }  
    },
    handleTheadStyle({ row, column, rowIndex, columnIndex}) {
      if (!this.mutilSort) return;
      if (this.activeThead[column.property]) {
          column.order = this.activeThead[column.property].order;
      }
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Zero0985

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值