<basic-table
:span-method="objectSpanMethod"
>
private spanAll: any[]=[];// 所有要合并的数量(一行一行的开始)
private mounted () {
this.getSpanNum();
}
private objectSpanMethod ({ row, column, rowIndex, columnIndex }: {row: FailureModel; column: any; rowIndex: number; columnIndex: number}) {
if (columnIndex === 0) {
const rowNum = this.spanAll[rowIndex];
const colNum = rowNum > 0 ? 1 : 0;
return {
// eslint-disable-next-line spellcheck/spell-checker
rowspan: rowNum,
// eslint-disable-next-line spellcheck/spell-checker
colspan: colNum
};
}
}
private getSpanNum () {
this.spanAll = [];
const data = this.data;
let samePosition = 0;
data.forEach((val: FailureModel, i: number) => {
if (i === 0) {
this.spanAll.push(1);
samePosition = 0;
} else {
if (data[i].name === data[i - 1].name) {
this.spanAll[samePosition] += 1;
this.spanAll.push(0);
} else {
this.spanAll.push(1);
samePosition = i;
}
}
});
}
ele 合并表格
最新推荐文章于 2023-03-28 18:31:39 发布