<el-table :span-method="arraySpanMethod"></el-table>
//1.列---相同数据合并
arraySpanMethod({ row, column, rowIndex, columnIndex }){
//第一列相同数据合并
if(columnIndex == 0){
// 表格数据修改
const _row = this.flitterData(this.searchData,'storeName').one[rowIndex]
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col,
};
}
}
flitterData(arr,mergeName) {
let spanOneArr = [];
let concatOne = 0;
arr.forEach((item, index) => {
if (index === 0) {
spanOneArr.push(1);
} else {
// item.storeName 第一列要渲染的值
if (item[mergeName] === arr[index - 1][mergeName]) {
//第一列需合并相同内容的判断条件
spanOneArr[concatOne] = spanOneArr[concatOne] + 1;
spanOneArr.push(0);
} else {
spanOneArr.push(1);
concatOne = index;
}
}
});
return {
one: spanOneArr,
};
},