el-table合并行

需求:

1、”用户任务“中的”代码“需要按照升序进行排列;
2、”用户任务“中连续的”会签“是共用一个序号,并且序号进行合并

效果

在这里插入图片描述

解决方法

列表排序一般是前端传值,后端进行排序。由于后端返回的表格列表没有 序号indexNum 这个字段,我是自己做的一个处理去进行添加,方便后续相同序号的合并

--ListTable.ts--
// 获取表格列表以及添加序号indexNum
  search(resetPaging: boolean) {
    if (resetPaging) {
      this.paging.page = 1;
    }
    let params = this.buildFilter();
    let loading = this.$loading(ConstantMgr.loadingOption);
    UserTaskInsApi.query(params)
      .then((res) => {
        if (res.success) {
          let dataList = res.data!;
          this.index = 1;
          this.tempIndex = 0;
          dataList.forEach((item: any, index) => {
            if (index === 0) {
              item.indexNum = this.index;
              this.tempIndex = this.index;
              this.index++;
              this.temp = item;
            } else {
              if (item.bpmUserTaskDefinitionId !== this.temp.bpmUserTaskDefinitionId) {
                item.indexNum = this.index;
                this.tempIndex = this.index;
                this.index++;
              } else {
                item.indexNum = this.tempIndex;
              }
            }
            // this.index++;
            this.temp = item;
          });
          this.records = dataList;
          console.log('records=>', this.records);
        }
      })
      .catch((err) => {
        this.$message.error(err.message);
      })
      .finally(() => {
        loading.close();
      });
  }

// 相同序号进行合并
  onMergeLines(records) {
    this.spanArr = [];
    this.position = 0;
    records.forEach((item, index) => {
      if (index === 0) {
        this.spanArr.push(1);
        this.position = 0;
      } else {
        if (records[index].indexNum === records[index - 1].indexNum) {
          this.spanArr[this.position] += 1; // 合并行
          this.spanArr.push(0);
        } else {
          this.spanArr.push(1);
          this.position = index;
        }
      }
    });
  }
  objectSpanMethod({ row, column, rowIndex, columnIndex }) {
    if (columnIndex === 0) { // 如果是第一列也就是序号那列就进行合并
      const _row = this.spanArr[rowIndex];
      const _col = _row > 0 ? 1 : 0;
      return {
        rowspan: _row,
        colspan: _col,
      };
    }
  }



--ListTable.vue--

 <el-table  :data="records" :span-method="objectSpanMethod" ……>
     ……
  </el-table>

推荐资料 :https://element.eleme.cn/#/zh-CN

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

*neverGiveUp*

你的鼓励是我最大的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值