1、将所有一样的列进行合并
data(){
return{
// 合并列表的规则
mergeObj:{},
}
}
// 列表合并规则判断
getSpanArr (data) {
this.mergeArr.forEach((key, index1) => {
let count = 0
this.mergeObj[key] = []
data.forEach((item, index) => {
if (index === 0) {
this.mergeObj[key].push(1)
} else {
if (item[key] === data[index - 1][key]) {
this.mergeObj[key][count] += 1
this.mergeObj[key].push(0)
} else {
count = index
this.mergeObj[key].push(1)
}
}
})
},
// 列表合并方法
objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
if (this.mergeArr.indexOf(column.property) !== -1) {
if (this.mergeObj[column.property][rowIndex]) {
return [this.mergeObj[column.property][rowIndex], 1]
} else {
return [0, 0]
}
}
},
2、针对某几个相同的值 进行合并,其他相同不合并
data(){
return{
// 合并列表的规则
mergeObj:{},
// 需要合并的字段
mergeArr:['companyName','inboundOrderNo','inboundDate','createUserId','supplierCode','type','accountSign','accountTime','voucherNo'],
}
}
// 列表合并规则判断
getSpanArr (data) {
this.mergeArr.forEach((key, index1) => {
let count = 0
this.mergeObj[key] = []
data.forEach((item, index) => {
if (index === 0) {
this.mergeObj[key].push(1)
} else {
if (item[key] === data[index - 1][key]) {
this.mergeObj[key][count] += 1
this.mergeObj[key].push(0)
} else {
count = index
this.mergeObj[key].push(1)
}
}
})
// 把需要合并的字段合并
this.mergeArr.forEach(key=>{
this.mergeObj[key] = this.mergeObj.inboundOrderNo
})
},
// 列表合并方法
objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
if (this.mergeArr.indexOf(column.property) !== -1) {
if (this.mergeObj[column.property][rowIndex]) {
return [this.mergeObj[column.property][rowIndex], 1]
} else {
return [0, 0]
}
}
},
因篇幅问题不能全部显示,请点此查看更多更全内容