复杂的el-table表格合并
//原来的类型 tableData:[index:1,aa:‘xxx’,type:[{cNum:‘’,Cz:‘’}]
getData() {
let arr = this.tableData;
let str = [];
let newArr = [];
arr.filter((value, index, array) => {
if (value.type.length > 1 && value.type.length != 0) {
for (let j = 0; j < value.type.length; j++) {
var db = {
name: value.name,
num: value.num,
numTwo: value.numTwo,
type: [value.type[j]]
};
str.push(db);
}
value.type = [];
arr.splice(index, 1);
arr.splice(index, 0, …str);
newArr = str;
} else {
newArr = arr;
}
});
// this.$set(this, ‘list’, newArr);
this.getSpanArr(newArr);
},
getSpanArr(data) {
this.spanArr = [];
for (var i = 0; i < data.length; i++) {
if (i === 0) {
this.spanArr.push(1);
this.pos = 0;
} else {
if (data[i].name === data[i - 1].name) {
this.spanArr[this.pos] += 1;
this.spanArr.push(0);
} else {
this.spanArr.push(1);
this.pos = i;
}
}
}
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2 || columnIndex === 3) {
//合并行的行为在第一列、第二列、第三列、第四列进行
const _row = this.spanArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col
};
}
},