el-table合并行合并列

1.合并多行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
objectSpanMethod ({ row, column, rowIndex, columnIndex }, list) {
  // console.log("objectSpanMethod", columnIndex, list)
  if (columnIndex === 4 || columnIndex === 5 || columnIndex === 6) {
    if (rowIndex == 0) {
      return {
        rowspan: list.length,
        colspan: 1
      };
    } else {
      return {
        rowspan: 0,
        colspan: 0
      };
    }
  }
 
},

 

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
//动态合并行
   objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
     // columnIndex === xx 找到第xx列,实现合并随机出现的行数
     if (columnIndex === 4) {
       const _row = this.spanArr[rowIndex];
       const _col = _row > 0 ? 1 : 0;
       return {
         rowspan: _row,
         colspan: _col
       };
     }
   },
   // 因为要合并的行数是不固定的,此函数是实现合并随意行数的功能
   getSpanArr () {
       this.spanArr=[]
       let pos = 0
       for (var i = 0; i < this.dataTable.length; i++) {
         if (i === 0) {
           // 如果是第一条记录(即索引是0的时候),向数组中加入1
           this.spanArr.push(1);
           pos = 0;
         } else {
           if (this.dataTable[i].name=== this.dataTable[i - 1].name) {
             this.spanArr[pos] += 1;
             this.spanArr.push(0);
           } else {
             // 不相等push 1
             this.spanArr.push(1);
             pos = i;
           }
         }
     }
   },

  

 

2.合并多列

1
2
3
4
5
6
7
8
9
objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
     if (row.pushType == 2) {
       if (columnIndex == 3) {
         return [1, 4]
       } else if (columnIndex == 4 || columnIndex == 5 || columnIndex == 6) {
         return [0, 0]
       }
     }
   },

  

 

posted @   枫若  阅读(66)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
历史上的今天:
2021-04-21 将本地项目上传到gitee
点击右上角即可分享
微信分享提示