Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
714 views
in Technique[技术] by (71.8m points)

element table 合并属性span-method,在可动态手动添加一条数据情况下如何进行合并单元格

image.png
表格可在当前选择下新增行后相同的列会进行单元格合并,在一开始只有静态数据下课实现,一旦动态新增,合并单元格就会错乱了?请问如何使我在第一个指标列下点击新增,将会在第3行下新增一行之后并合并指标项单元格

    // 查找出合并的列
    getSpanArr(data) {
      for (let i = 0; i < data.length; i++) {
        if (i === 0) {
          this.spanArr.push(1)
          this.pos = 0
        } else {
          // 判断当前元素与上一个元素是否相同
          if (data[i].id === data[i - 1].id) {
            this.spanArr[this.pos] += 1
            this.spanArr.push(0)
          } else {
            this.spanArr.push(1)
            this.pos = i
          }
        }
        console.log('this.spanArr', this.spanArr)
      }
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      // 合并单元格
      if (columnIndex === 1) {
        const _row = this.spanArr[rowIndex]
        console.log('this.spanArr[rowIndex]', this.spanArr[rowIndex])
        const _col = _row > 0 ? 1 : 0
        console.log(`rowspan:${_row} colspan:${_col}`)
        return { // [0,0] 表示这一行不显示, [2,1]表示行的合并数
          rowspan: _row,
          colspan: _col,
        }
      }
    },
    addTarget(row, index) {
      console.log('index', index)
      console.log(row, this.tableData[index])
      this.tableData.splice(index + 1, 0, { id: row.id, name: '王小虎', status: 1 })
      this.$refs.plTable.doLayout()
      this.getSpanArr(this.tableData)
      console.log('this.tableData', this.tableData)
    },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

之前遇到过这个问题,写了篇文章记录,供你参考,有问题沟通哈~
Element 表格动态合并并行或列的方式


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...