因为官网给的代码是根据相同行项目进行合并行,但是实际情况不只是合并一列的行项目,后置的列需要根据前置列进行合并,上代码
mergeRowMethod ({ row, _rowIndex, column, visibleData }) {
const fields = ['date', 'total']
const cellValue = row[column.property]
if (cellValue && fields.includes(column.property)) {
const prevRow = visibleData[_rowIndex - 1]
let nextRow = visibleData[_rowIndex + 1]
if (column.property === 'date') {
if (prevRow && prevRow[column.property] === cellValue) {
return { rowspan: 0, colspan: 0 }
} else {
let countRowspan = 1
while (nextRow && nextRow[column.property] === cellValue) {
nextRow = visibleData[++countRowspan + _rowIndex]
}
if (countRowspan > 1) {
return { rowspan: countRowspan, colspan: 1 }
}
}
} else if (column.property === 'total') {
if (prevRow && prevRow[column.property] === cellValue && prevRow.date === row.date) {
return { rowspan: 0, colspan: 0 }
} else {
let countRowspan = 1
while (nextRow && nextRow[column.property] === cellValue && nextRow.date === row.date) {
nextRow = visibleData[++countRowspan + _rowIndex]
}
if (countRowspan > 1) {
return { rowspan: countRowspan, colspan: 1 }
}
}
}
}