Element UI 里的el-table表格排序

后台管理有时候会有排序的需求,如果只针对当前页进行排序,那么前端就可以实现排序,在对应需要排序的字段中,使用sortable字段即可,但是如果存在分页的情况,就只能排序展示页的内容,无法所有数据排序,这时候我们就要使用后端排序了。

一、给el-table设置事件 @sort-change="changeTableSort"

<el-table v-if='activate==4' 
   :data="tableData.body"
    border
    @sort-change="changeTableSort"
        >
</el-table>

二、给需要排序的表格设置属性 sortable="custom"

 <el-table-column align="center" 
    label="总佣金金额" 
    prop="commissionPrice"
    width='150' 
    sortable="custom"
          >
 </el-table-column>

三、声明 changeTableSort()

   //排序
    changeTableSort(column){
      console.log(column)
      if(column.order=='descending'){
        this.sorting='desc'
      }else if(column.order=="ascending"){
        this.sorting='asc'
      }
      this.prop=column.prop
      this.getTableData4()
    },


     // 邀请明细接口
    getTableData4() {
      let params = {
        size: this.queryParams.size, //每页显示条数
        current: this.queryParams.current, //当前页
        userNo:this.$route.query.userNo,
        orderBy:this.prop,
        sortingRules:this.sorting
      }
      this.$api.customerAccountMgmt.inviteDetail(params).then(res => {
        if (res.code == 200) {
          this.tableData.loading = false
          let resData = res.data
          this.tableData.body = resData.records
          this.total = resData.total;
          this.indexStartNum = ((this.queryParams.current) * this.size) - 1
          if (this.total > 0) {
            this.pagination = true
          } else {
            this.pagination = false
          }
          this.startRow = resData.startRow;
          this.endRow = resData.endRow;

        } else {
          this.common.messageTipCode(res, 'error');
        }

      })
    },

打印出的数据为

order:排序的方式 ascending == 升序 descending == 降序 null == 不排序

prop:排序的那个表格的字段名

我把我的接口传参贴出来,上面的代码可以结合此图进行理解。

可以根据打印出来的值,和后端让我们传给他的参数,进行处理,就能实现排序功能。

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

阿wei程序媛

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

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

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

打赏作者

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

抵扣说明:

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

余额充值