element table动态合并

el-table标签内加入:
:span-method="objectSpanMethod"
 
定义初始化要合并列的对象:

    data(){
        return{
            tarr1:[],
            tarr2:[],
            tarr3:[],
            tarr4:[],
            tarr5:[],
            tarr6:[],
            tarr7:[],
            position1:0,
            position2:0,
            position3:0,
            position4:0,
            position5:0,
            position6:0,
            position7:0,
}
}

处理后台查询的数据:

                this.dialogFormVisibletableData=response.data.info
                this.rowspan(this.tarr1,this.position1,'ONAME')
                this.rowspan(this.tarr2,this.position2,'HAZARD_DEP')
                this.rowspan(this.tarr3,this.position3,'HAZARD_LIABLE_PERSON')
                this.rowspan(this.tarr4,this.position4,'RISK_UNIT_NAME')
                this.rowspan(this.tarr5,this.position4,'RISK_EVENT_NAME')
                this.rowspan(this.tarr6,this.position5,'CLASSIFY1')
                this.rowspan(this.tarr7,this.position6,'CLASSIFY2')
   rowspan(spanArr, position, spanName) {
      this.tableData.forEach((item, index) => {
        if (index === 0) {
          spanArr.push(1);
          position = 0;
        } else {
          if (
            this.tableData[index][spanName] === this.tableData[index - 1][spanName]
          ) {
            spanArr[position] += 1;
            spanArr.push(0);
          } else {
            spanArr.push(1);
            position = index;
          }
        }
      });
    },
  objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 1) {
        const _row = this.tarr1[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        console.log(_row, _col, "row col");
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
      if (columnIndex === 2) {
        const _row = this.tarr2[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    if (columnIndex === 3) {
        const _row = this.tarr3[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    if (columnIndex === 4) {
        const _row = this.tarr4[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
    if (columnIndex === 5) {
        const _row = this.tarr5[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }
     if (columnIndex === 6) {
        const _row = this.tarr6[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };
      }     
    if (columnIndex === 7) {
        const _row = this.tarr7[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col,
        };

 

posted @ 2022-04-27 16:36  _Lawrence  阅读(261)  评论(0编辑  收藏  举报