el-table行列合并原理

el-table和并相同数据的行单元格

rowspan为当前单元格所需要的合并的行数(包括本行),若当前行的rowspan为n(n不为0),后面的n-1行的rowspan则需要为0。如当前行的rowspan为3,则后面2行的rowspan需要为0

colspan同理

methods:{
    filterData(arr, key) {
      let result = [];
      let concatOne = 0;
      arr.forEach((item, index) => {
        if (index === 0) {
          result.push(1);
        } else {
		  // key为'extraCost'是数组	
          if (key === "extraCost") {
            const nowExtra = item[key].toString();
            const preExtra = arr[index - 1][key].toString();
            if (nowExtra === preExtra) {
              result[concatOne] += 1;
              result.push(0);
            } else {
              result.push(1);
              concatOne = index;
            }
          } else {
            if (item[key] === arr[index - 1][key]) {
              result[concatOne] += 1;
              result.push(0);
            } else {
              result.push(1);
              concatOne = index;
            }
          }
        }
      });
      return result;
    },
    objectSpanMethod({ rowIndex, columnIndex }) {
      let _row, _col;
      if (columnIndex === 3) {
        _row = this.filterData(this.basicCostData, "leastTime")[rowIndex];
        _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
      if (columnIndex === 4) {
        _row = this.filterData(this.basicCostData, "basicCost")[rowIndex];
        _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
      if (columnIndex === 5) {
        _row = this.filterData(this.basicCostData, "extraCost")[rowIndex];
        _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    },
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值