el-table合并单元格

 <el-table
            ref="dictNewList"
            :data="formData.dictTable"
            size="mini"
            border
            :span-method="spanMethod"
          >
            <el-table-column label="系统">
              <template slot-scope="scope">
                {{ formData.systemName }}
              </template>
            </el-table-column>
            <el-table-column label="字典标识">
              <template slot-scope="scope">
                <el-input v-model="scope.row.dictIdentifier" @blur="validateDictRow(scope.row)"
                          :class="{ 'is-invalid': scope.row.invalid }">>
                </el-input>
              </template>
            </el-table-column>
            <el-table-column label="字段名称">
              <template slot-scope="scope">
                <el-input v-model="scope.row.fieldName" @blur="validateDictRow(scope.row)"
                          :class="{ 'is-invalid': scope.row.invalid }"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="字段描述">
              <template slot-scope="scope">
                <el-input v-model="scope.row.fieldDescription" @blur="validateDictRow(scope.row)"
                          :class="{ 'is-invalid': scope.row.invalid }"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="字段值">
              <template slot-scope="scope">
                <el-input v-model="scope.row.fieldValue" @blur="validateDictRow(scope.row)"
                          :class="{ 'is-invalid': scope.row.invalid }"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="值描述">
              <template slot-scope="scope">
                <el-input v-model="scope.row.valueMeaning" @blur="validateDictRow(scope.row)"
                          :class="{ 'is-invalid': scope.row.invalid }"></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="80px">
              <template slot-scope="scope">
                <el-button type="text" @click="deleteDictRow(scope.$index)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-button type="primary" @click="addNewDictRow" style="margin-top: 10px">新增</el-button>
// 合并字典list相同的行
    calculateRowSpan(operTable) {
      let span = 1;
      let lastRow = null;
      let lastSpanStart = 0;
      let tempRowSpanInfo = new Array(operTable.length).fill(0);
      operTable.forEach((row, index) => {
        if (lastRow && this.isSameGroup(lastRow, row)) {
          span++;
        } else {
          if (lastRow) {
            tempRowSpanInfo[lastSpanStart] = span;
          }
          lastSpanStart = index;
          span = 1;
        }
        lastRow = row;
      });
      tempRowSpanInfo[lastSpanStart] = span;
      this.rowSpanInfo = tempRowSpanInfo;
    },
    isSameGroup(row1, row2) {
      if (!row1.dictIdentifier) // 如果两行都为空
        return false;
      return row1.dictIdentifier === row2.dictIdentifier
    },
    spanMethod({row, column, rowIndex, columnIndex}) {
      if (columnIndex < 4) {
        return {
          rowspan: this.rowSpanInfo[rowIndex], colspan: 1
        };
      }
    },
    ```
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值