<el-table
:data="tableData"
:span-method="handleSpanMethod">
</el-table>
handleSpanMethod ({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
const _row = (this.filtterData(this.tableData,['key1']))[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
} else if (columnIndex === 1) {
const _row = (this.filtterData(this.tableData,['key1', 'key2']))[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
}
},
filtterData (arr, keyArr) {
let resArr = []
let concatIndex = 0
arr.forEach((item, index) => {
if (index === 0) {
resArr.push(1)
} else {
let i = keyArr.length
keyArr.map(key => {
if (item[key] === arr[index - 1][key]) {
i--
}
})
if (i === 0) {
resArr[concatIndex] += 1
resArr.push(0)
} else {
resArr.push(1)
concatIndex = index
}
}
})
return resArr
},