html : el-table :header-cell-style="{background:'#6d7f93',color:'white'}" :data="ptableDate" align="center" border v-loading="loading" :height="tableHeight" :span-method="objectOneMethod" el-table-column align="center" show-overflow-toolt
html :
<el-table :header-cell-style="{background:'#6d7f93',color:'white'}" :data="ptableDate" align="center" border v-loading="loading" :height="tableHeight" :span-method="objectOneMethod" > <el-table-column align="center" show-overflow-tooltip prop="projName" ></el-table-column> <el-table-column align="center" show-overflow-tooltip prop="dirtySection" ></el-table-column> <el-table-column align="center" show-overflow-tooltip prop="towerNumber" ></el-table-column> <el-table-column align="center" show-overflow-tooltip prop="inclination" ></el-table-column> </el-table>
method
objectOneMethod({ row, column, rowIndex, columnIndex }) { if (columnIndex === 0) { const _row = this.setTable(this.ptableDate).one[rowIndex]; const _col = _row > 0 ? 1 : 0; return { rowspan: _row, colspan: _col }; } if (columnIndex === 1 ) { const _row = this.setTable(this.ptableDate).two[rowIndex]; const _col = _row > 0 ? 1 : 0; return { rowspan: _row, colspan: _col }; } }, setTable(tableData) { let spanOneArr = [], spanTwoArr = [], concatOne = 0, concatTwo = 0; tableData.forEach((item, index) => { if (index === 0) { spanOneArr.push(1); spanTwoArr.push(1); } else { if (item.projName === tableData[index - 1].projName) { //第一列需合并相同内容的判断条件 spanOneArr[concatOne] += 1; spanOneArr.push(0); } else { spanOneArr.push(1); concatOne = index; } if (item.dirtySection === tableData[index - 1].dirtySection) { //第二列和需合并相同内容的判断条件 spanTwoArr[concatTwo] += 1; spanTwoArr.push(0); } else { spanTwoArr.push(1); concatTwo = index; } } }); return { one: spanOneArr, two: spanTwoArr }; },
ps:下面看下ELEMENT-UI 合并单元格的方法
arraySpanMethod({ row, column, rowIndex, columnIndex }) { // 只合并区域位置 //columnIndex 横的第一列 //rowIndex 竖的数组的length % 3 ==0 合并单元格 if (columnIndex === 0) { //如果是第一行 if (rowIndex % 3 === 0) {//如果是 数组长度 % 3 ==0 return { rowspan: 3, colspan: 1 }; } else { return { rowspan: 0, colspan: 0 }; } } },
总结
以上所述是小编给大家介绍的vue 中 elment-ui table合并上下两行相同数据单元格,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对易盾网络网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!