:span-method=“objectSpanMethod”
// 合并行开始
getSpanArr(data) {
this.spanArr = []
for (var i = 0; i < data.length; i++) {
if (i === 0) {
this.spanArr.push(1)
this.pos = 0
} else {
// 判断当前元素与上一个元素是否相同
//TYSHXYDM为用于判断值是否相同的字段,若该字段的值相同,则对其进行合并操作
if (data[i].TYSHXYDM === data[i - 1].TYSHXYDM) {
this.spanArr[this.pos] += 1
this.spanArr.push(0)
} else {
this.spanArr.push(1)
this.pos = i
}
}
}
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
//if中的条件为需要进行合并的字段索引
if (
columnIndex === 0 ||
columnIndex === 1 ||
columnIndex === 2 ||
columnIndex === 3 ||
columnIndex === 4 ||
columnIndex === 5 ||
columnIndex === 6 ||
columnIndex === 7 ||
columnIndex === 8
) {
const _row = this.spanArr[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
// [0,0] 表示这一行不显示, [2,1]表示行的合并数
rowspan: _row,
colspan: _col,
}
}
},