el-table自定义合并行

废话少说直接上效果图

实现代码

<el-table
      :data="tableData"
      style="width: 100%"
      :span-method="arraySpanMethodHeatstation"
    >

 具体想怎么合并根据需求进行字段和行列的判断

const arraySpanMethodHeatstation = ({
  row,
  column,
  rowIndex,
  columnIndex,
}: any) => {
  if (columnIndex == 0) {
    let currentCategory: any = row.heatYear;
    let nextRow: any = tableData.value[rowIndex - 1];
    if (nextRow && nextRow.heatYear == currentCategory) {
      return [0, 0];
    } else {
      let count = 1;
      while (
        tableData.value[rowIndex + count] &&
        tableData.value[rowIndex + count].heatYear === currentCategory
      ) {
        count++;
      }
      return [count, 1];
    }
  }

  if (columnIndex == 1) {
    let currentCategory: any = row.userType;
    let nextRow: any = tableData.value[rowIndex - 1];
    if (nextRow && nextRow.userType == currentCategory) {
      return [0, 0];
    } else {
      let count = 1;
      while (
        tableData.value[rowIndex + count] &&
        tableData.value[rowIndex + count].userType === currentCategory
      ) {
        count++;
      }
      return [count, 1];
    }
  }
  if (columnIndex === 9) {
    if (rowIndex % 4 === 0) {
      return {
        rowspan: 4,
        colspan: 1,
      };
    } else {
      return {
        rowspan: 0,
        colspan: 0,
      };
    }
  }
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值