element-ui 合并单元格
作者:互联网
html:
<el-table
:data="dataList"
style="width: 100%;"
:span-method="spanMethod"
>
</el-table>
data:
spanArr:[]
methods:
getSpanArr (data) {
this.spanArr = []
if (data == null) {
return
}
for (var i = 0; i < data.length; i++) {
if (i === 0) {
this.spanArr.push(1)
this.pos = 0
} else {
// 判断当前元素与上一个元素是否相同 card:相同的字段
if (data[i].card === data[i - 1].card) {
this.spanArr[this.pos] += 1
this.spanArr.push(0)
} else {
this.spanArr.push(1)
this.pos = i
}
}
}
},
spanMethod ({ row, column, rowIndex, columnIndex }) {
if (columnIndex < 4) {
const _row = this.spanArr[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
}
},
标签:spanArr,单元格,pos,element,ui,push,data,card,row 来源: https://blog.csdn.net/qq_41979331/article/details/119061820