element-ui合并相同名称el-table单元格

element-ui合并相同名称el-table单元格 

  • 效果图如下

  • 需要用element-ui中 span-method= " " 方法

  • 代码如下

  • 如果数据拿到的是乱的,没有经过排序,可以将后端返回的数据进行一个排序(看自己需求),代码供上如下:

// this.arr是所有数据
this.arr.sort((a,b)=>{ 
  if(a['fxdid'] != b['fxdid']){    // fxdid需要排序的属性(字符串排序)
    return a['fxdid'].localeCompare(b['fxdid']);
  }
})
  •  不排序可直接进行下面代码操作

// 合并单元格
      flitterData(arr){
        let spanOneArr = [],
        spanTwoArr = [],
        spanThreeArr = [],
        concatOne = 0,
        concatTwo = 0
        concatThree =0;
        arr.forEach((item,index)=>{
          if(index === 0){
            spanOneArr.push(1);
            spanTwoArr.push(1);
            spanThreeArr.push(1);
          }else{
            // fxdlx 是你需要合并的参数
            if(item.fxdlx === arr[index - 1].fxdlx){ //第一列需合并相同内容的判断条件 
              spanOneArr[concatOne] += 1;
              spanOneArr.push(0);
            }else{
              spanOneArr.push(1);
              concatOne = index;
            };
            // fxdid 是你需要合并的参数
            if(item.fxdid === arr[index - 1].fxdid&&item.fxdlx === arr[index - 1].fxdlx){//第二列需合并相同内容的判断条件
              spanTwoArr[concatTwo] += 1;
              spanTwoArr.push(0);
            }else{
              spanTwoArr.push(1);
              concatTwo = index;
            };
            if(item.fxdid === arr[index - 1].fxdid&&item.zybz === arr[index - 1].zybz){ //第三列需合并相同内容的判断条件
             spanThreeArr[concatThree] += 1;
             spanThreeArr.push(0);
            }else{
              spanThreeArr.push(1);
              tThree = index;
            };
          }
        });
        return  {
            one: spanOneArr,
            two: spanTwoArr,
            three: spanThreeArr
        }
    },
    // 合并单元格
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      if(columnIndex === 1 ) {
        const _row = (this.flitterData(this.arr).one)[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if(columnIndex === 2) {
        const _row = (this.flitterData(this.arr).two)[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
      if(columnIndex === 3) {
        const _row = (this.flitterData(this.arr).three)[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        };
      }
    },

 

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值