elementui table 相同名字的行 合并;
<el-table :data="tableData :span-method="mergeRows" > <el-table-column prop="deptName" label="油(气)田"> </el-table-column> </el-table>
flitterData (arr, name) {
let spanOneArr = []
let concatOne = 0
arr.forEach((item, index) => {
if (index === 0) {
spanOneArr.push(1)
} else {
if (item[name] === arr[index - 1][name]) {
spanOneArr[concatOne] += 1
spanOneArr.push(0)
} else {
spanOneArr.push(1)
concatOne = index
}
}
})
return {
one: spanOneArr,
}
},
mergeRows ({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
const _row = this.flitterData(this.tableData, 'deptName').one[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col,
}
}
},