el-tabel合并指定行、列单元格数据;合并列后不见了一列数据问题

 <el-table :span-method="cellMerge" :key="tableKey" v-loading="tyyyLoading" :data="tyyyData" border :header-cell-style="rowClass" :cell-style="cellStyle">
          <el-table-column v-for="(item, index) in tyyyTableList" :key="index" align="center" :label="item.label">
            <template slot-scope="scope">
              <span :title="scope.row[`${item.prop}`]" style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis">{{ scope.row[item.prop] }}</span>
            </template>
          </el-table-column>
        </el-table>

2、写法

   // 获取相同名称的个数 tableData: 表格的数据, projectName: 确定相同的参数
    cellMerge({ row, column, rowIndex, columnIndex }) {
      if ( (rowIndex === 0 || rowIndex == 5) && columnIndex === 0) {
        return [1, 2];
      } else if ((rowIndex === 0 || rowIndex == 5) && columnIndex === 1) {
      return [0,2]; // 再把前面合并了的那一列删了,这样错位的再错回来,往前一列又对了
    } else if (columnIndex === 0) {
        const _row = this.spanArr[rowIndex]// 处理除了第一行和第五行外的单元格和合并,但是也只是合并第一列的产品类型相同的数据
        const _col = 1
        return {
          rowspan: _row,
          colspan: _col,
        }
    } else {
      return [1, 1];//其他单元格都独立显示
    }
    },
    // 单元格的处理方法 当前行row、当前列column、当前行号rowIndex、当前列号columnIndex
    getSpanArr(data) {
    for (let i = 0; i < data.length; i++) {
      if (i === 0) {
        this.spanArr = [];
        this.spanArr.push(1);
        this.pos = 0;
      } else {
        if (data[i].productTypeDesc === data[i - 1].productTypeDesc) {
          this.spanArr[this.pos] += 1;
          this.spanArr.push(0);
        } else {
          this.spanArr.push(1);
          this.pos = i;
        }
      }
    }
    return this.spanArr; // 返回合并信息数组
  },

3 、最终效果

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值