getSpanArr(data) {
this.objColspan = {};
let colPos = 0;
for (var i = 0; i < data.length; i++) {
this.objColspan[i] = [];
let filterData = JSON.parse(JSON.stringify(data[i]));
let objValues = [];
// keys push到数组
this.tableHeaderData.forEach(element => {
objValues.push(filterData[element.prop]);
});
objValues.forEach((item,index) => {
if (index == 0) {
this.objColspan[i].push(1);
colPos = 0;
} else {
// 判断当前元素与上一个元素是否相同
if (item != '' && item == objValues[index - 1]) {
this.objColspan[i][colPos] += 1;
this.objColspan[i].push(0);
} else {
this.objColspan[i].push(1);
colPos = index;
}
}
});
}
},
arraySpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex > 8) {
const _col = this.objColspan[rowIndex][columnIndex - 9];
return {
rowspan: _col > 0 ? 1 : 0,
colspan: _col
};
}
}
el-table 合并单元格
最新推荐文章于 2024-06-21 11:27:06 发布