element的table合并第一列万能用法
!!!一定要看这段解释
看到下面这里需要修改的地方
this.selectList是具体到循环的数组
'colorID’是我需要判断的键值对,要加引号,不然会被判断为变量,改成你需要判断的键值对
<el-table :span-method="objectSpanMethod"></el-table>
// 合并行
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
// 如果是第一行
if (columnIndex === 0) {
const _row = this.filterSpan(this.selectList, 'colorID')[rowIndex] // 这里需要修改
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
}
},
// 处理数据
filterSpan(arr, condition) {
const spanOneArr = []
let concatOne = 0
arr.map((item, index) => {
if (index === 0) {
spanOneArr.push(1)
} else {
// 第一列需合并相同内容的判断条件
if (item[condition] === arr[index - 1][condition]) {
spanOneArr[concatOne] += 1
spanOneArr.push(0)
} else {
spanOneArr.push(1)
concatOne = index
}
}
})
return spanOneArr
},
效果图
如果有用,请给我点赞收藏,我会很开心,谢谢