根据官网文档 customRender 进行自定义
声明列:
columns: [
{
title: '问题类别',
dataIndex: 'problemType',
customRender: (value, row, index) => {
const obj = {
children: value,
attrs: {}
}
obj.attrs.rowSpan = this.mergeCells(value, 'problemType', index)
return obj
}
},
{
title: '问题描述',
dataIndex: 'problemInfo',
customRender: (value, row, index) => {
const obj = {
children: value,
attrs: {}
}
obj.attrs.rowSpan = this.mergeCells(value, 'problemInfo', index)
return obj
}
}
]
// 根据相同数据计算需要合并的行数
mergeCells (text, key, index) {
if (index !== 0 && text === this.data[index - 1][key]) {
return 0
}
let rowSpan = 1
for (let i = index + 1; i < this.data.length; i++) {
if (text !== this.data[i][key]) {
break
}
rowSpan++
}
return rowSpan
}
效果如图