elementui 合并行和列

//表格合同方法 --- 此处只合并了第一列
objectSpanMethod({ row, column, rowIndex, columnIndex }){
    if (columnIndex === 0) {
      const _row = this.spanArr[rowIndex];
      const _col = _row > 0 ? 1 : 0;
      return {
        rowspan: _row,
        colspan: _col
      };
    }

  },

//筛出行里面相同的数据的index  并组装进数组--------请求完表格数据后调用一下这个方法
 rowspan() {
    this.tableData.forEach((item, index) => {
      if (index === 0) {
        this.spanArr.push(1);
        this.position = 0;
      } else {
        if (this.tableData[index].name=== this.tableData[index - 1].name) {
          this.spanArr[this.position] += 1;
          this.spanArr.push(0);
        } else {
          this.spanArr.push(1);
          this.position = index;
        }
      }
    });
  },

表格单选

 //  @select="select"   ref="myInventory"
select(selection, row) {
  this.$refs.myInventory.clearSelection();
  if (selection.length == 0) return;
  row.editable = true; // 选中行可输入
  this.$refs.myInventory.toggleRowSelection(row, true);
},

你可能感兴趣的:(elementui 合并行和列)