vue-element table 合并单元格


  export default { 

    data() { 

      return { 

        tableData6: [ 

          { 

            id: '12987122', 

            name: '王小虎', 

            amount1: '234', 

            amount2: '3.2', 

            amount3: 10 

          }, 

          { 

            id: '12987122', 

            name: '王小虎', 

            amount1: '165', 

            amount2: '4.43', 

            amount3: 12 

          }, 

          { 

            id: '12987122', 

            name: '王小虎', 

            amount1: '324', 

            amount2: '1.9', 

            amount3: 9 

          }, 

          { 

            id: '12987125', 

            name: '王小虎', 

            amount1: '621', 

            amount2: '2.2', 

            amount3: 17 

          }, 

          { 

            id: '12987126', 

            name: '王小虎', 

            amount1: '539', 

            amount2: '4.1', 

            amount3: 15 

          } 

        ], 

        column_row_offset: { 

          id: [3, 1, 1], 

          name: [2, 1, 1, 1], 

          amount1: [1, 1, 1, 1, 1], 

          amount2: [1, 1, 1, 1, 1], 

          amount3: [1, 1, 1, 1, 1] 

        }, 

        now_col_row_num: {}, 

        now_col_offset: {}, 


      }; 

    }, 

    methods: { 

      objectSpanMethod({ row, column, rowIndex, columnIndex }) { 

        if (!this.now_col_row_num[column.property]) { 

            if (!this.column_row_offset[column.property]) {// 假如column_row_offset中没有某一列合并规则,就不合并,根据实际情况而加by ly

                  return {

                    rowspan:1,

                    colspan:1

                  }

               }

          this.now_col_row_num[column.property] = Object.assign([], this.column_row_offset[column.property]); 

          let a = this.now_col_row_num[column.property].shift(); 

          this.now_col_offset[column.property] = a; 

          return { 

            rowspan: a, 

            colspan: 1 

          }; 

        } else if (rowIndex >= this.now_col_offset[column.property]) { 

          let a = this.now_col_row_num[column.property].shift(); 

          this.now_col_offset[column.property] += a; 

          return { 

            rowspan: a, 

            colspan: 1 

          }; 

        } else { 

          return { 

            rowspan: 0, 

            colspan: 0 

          }; 

        } 

      } 

    } 

  }; 



1.<el-table-column>中必须有prop属性

2.<el-table-column>不能使用show-overflow-tooltip(当内容过长被隐藏时显示 tooltip)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容