一般合并单元格可根据行和列指定合并便可,这篇讲的是 如果表格里有名字或者id或者code相同时进行合并。代码如下:
// 合并单元格 handleTableArr(data){ this.spanArr = []; let contactDot = 0; data.forEach((item,index) => { item.index = index; if(index === 0){ this.spanArr.push(1); }else{ if(item.groupCode === data[index - 1].groupCode){ this.spanArr[contactDot] +=1; this.spanArr.push(0); }else{ this.spanArr.push(1); contactDot = index; } } }); return data; }, //计算合并表格 objectSpanMethod({ row, column, rowIndex, columnIndex }){ if(columnIndex === 0){ const _row = this.spanArr[rowIndex]; const _col = _row>0?1:0; return{ rowspan:_row, colspan:_col } } }
<el-table class="cardProList" :span-method="objectSpanMethod" :data="cardInfo.rights" :header-cell-style="{background:‘rgba(251, 251, 252, 1)‘}"> <el-table-column prop="groupCode" label="套餐" align="center"> <template slot-scope="scope"> <span v-if="scope.row.isNum">套餐{{scope.row.groupCode}}</span> <span v-else>{{scope.row.groupCode}}</span> </template> </el-table-column> </el-table>
:span-method="objectSpanMethod" 调用合并方法。
handleTableArr直接对后台返回的数组进行操作就行
element---el-table 根据相邻行属性值是否相同合并单元格
原文:https://www.cnblogs.com/zhu-xl/p/14866006.html