el-table 合并单元格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      const length =
        this.newlist[this.saveindex].data.newTable.length -
        this.newlist[this.saveindex].data.tag_list_all.length
      // 新增:处理前两行前两列的合并
      if (rowIndex < length && columnIndex < 2) {
        if (columnIndex === 0) {
          return {
            rowspan: 1,
            colspan: 2 // 合并两列
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0 // 隐藏第二列的其他单元格(已被第一列合并)
          }
        }
      }
      if (columnIndex === 0 && rowIndex >= length) {
        const _row = this.flitterData(
          this.newlist[this.saveindex].data.newTable
        ).one[rowIndex]
        const _col = _row > 0 ? 1 : 0
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },
    flitterData(arr) {
      const spanOneArr = []
      let concatOne = 0
      arr.forEach((item, index) => {
        if (index === 0) {
          spanOneArr.push(1)
        } else {
          if (item.p_value === arr[index - 1].p_value) {
            // 第一列需合并相同内容的判断条件
            spanOneArr[concatOne] += 1
            spanOneArr.push(0)
          } else {
            spanOneArr.push(1)
            concatOne = index
          }
        }
      })
      return {
        one: spanOneArr
      }
    },

  

posted @   小小小小小前端  阅读(165)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-04-25 ajax. 通过后台接口 渲染数据
点击右上角即可分享
微信分享提示