示图:
文章来源地址https://www.toymoban.com/news/detail-753465.html
代码:
<el-table :data="tableData" border height="358px" :span-method="objectSpanMethod" style="width: 100%">
</el-table>
methods: {
//修改成需要合并的字段
getSpanArrList(list,code) {
if (list.length>0) {
const spanArrList = []
let totalNum = 0
list.map((item, index) => {
if (index === 0) {
spanArrList.push(1)
} else {
//code是要合并的条件
if (item[code] === list[index - 1][code]) {
spanArrList[totalNum] += 1
spanArrList.push(0)
} else {
spanArrList.push(1)
totalNum = index
}
}
})
return { totalNumBer: spanArrList }
}
},
//合并行
objectSpanMethod({row, column, rowIndex, columnIndex}) {
if (columnIndex === 0) {
const rowSpanNum = this.getSpanArrList(this.tableData,'storehouseId').totalNumBer[rowIndex]
const colSpanNum = rowSpanNum > 0 ? 1 : 0
return {
rowspan: rowSpanNum,
colspan: colSpanNum,
}
}
},
}
文章来源:https://www.toymoban.com/news/detail-753465.html
到了这里,关于element table表格根据同一个字段合并列(亲测有效,开箱即用~)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!