合并单元格

需求:
合并 相同名称的产品
在这里插入图片描述
先说下elementUI合并单元格的方法,先计算好要合并的行数rowspan,return {rowspan,colspan},其他的单元格return{0,0}

    getData(params) {
	  //临时数组,存放产品名称相同的数量
      this.tempArr = []
      getTableData(params).then(response => {
        this.tableData = response.data
        //获取到表格数据后,通过遍历获取各个产品的数量
        for (let i = 0; i < this.tableData.length; i++) {
          if (i === 0) {
            this.tempArr.push(1) 
          } else {
            //一样的产品Id就累加产品数量,用0补齐要合并的位置
            if (this.tableData[i].prod_id === this.tableData[i - 1].prod_id) {
              this.tempArr[pos] += 1 
              this.tempArr.push(0)
            } else {
              this.tempArr.push(1)
              pos = i
            }
          }
        }
      })
    },

    spanMethod({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 0) {
        if (this.tempArr[rowIndex]) {
          return {
            rowspan: this.tempArr[rowIndex],
            colspan: this.tempArr[rowIndex] > 0 ? 1 : 0,
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0,
          }
        }
      }
    },

合并固定的两行单元格

在这里插入图片描述

spanMethod({ row, column, rowIndex, columnIndex }){
      ...
      //12列之前合并起来
      if (columnIndex < 12) 
        if (rowIndex % 2 === 0) {
          return {rowspan: 2, colspan: 1}
        } else {
          return {rowspan: 0, colspan: 0}
        }
      }
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值