objectSpanMethod 中的4个参数row, column, rowIndex, columnIndex
看官方文档有的时候真的很懵
在控制 行 合并的时候 最主要的就是 rowIndex,columnIndex
话不多说上才艺
step1.展示效果
step2.data部分 tabledata表格数据
data() {
return {
tableData: [{
id: '00',
name: '王小虎',
amount1: '234',
amount2: '3.2',
amount3: 1
}, {
id: '01',
name: '王小虎',
amount1: '165',
amount2: '4.43',
amount3: 2
}, {
id: '02',
name: '王小虎',
amount1: '324',
amount2: '1.9',
amount3: 3
}, {
id: '03',
name: '王小虎',
amount1: '621',
amount2: '2.2',
amount3: 4
}, {
id: '04',
name: '王小虎',
amount1: '539',
amount2: '4.1',
amount3: 5
},{
id: '05',
name: '王小虎',
amount1: '621',
amount2: '2.2',
amount3: 6
}, {
id: '06',
name: '王小虎',
amount1: '539',
amount2: '4.1',
amount3: 7
},{
id: '07',
name: '王小虎',
amount1: '621',
amount2: '2.2',
amount3: 8
}, {
id: '08',
name: '王小虎',
amount1: '539',
amount2: '4.1',
amount3: 9
}, {
id: '09',
name: '王小虎',
amount1: '539',
amount2: '4.1',
amount3: 10
}],
oneAry: [4,0,0,0,1,2,0,2,0,1],
twoAry: [2,0,2,0,1,2,0,1,1,1]
};
},
这里表格不是关键,关键是 oneAry,twoAry
oneAry:第一列数据 10共10条数据
4,0,0,0,1,2,0,2,0,1:合4,消失,消失,消失,合1,合2,消失,合2,消失,合一
对于一列来说 第几行消失也代表的被合并 就是这么简单
twoAry:第二列数据 同上
图码结合 这里oneAry与step1一起看
step3:合并方法
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
const _row = this.oneAry[rowIndex];
const _col = _row>0?1:0;
console.log(_row,_col)
return{
rowspan: _row,
colspan: _col
}
}
if (columnIndex === 1) {
const _row = this.twoAry[rowIndex];
const _col = _row>0?1:0;
console.log(_row,_col)
return{
rowspan: _row,
colspan: _col
}
}
}
官方的修改下就好了
这里尤其要注意不要整体看 要一行一行的来看就行
比如 tabledata中第一条数据来了 _row=4,_col=1
第二来了,_row=0,_col=0; 因为他消失了(被合并了)
就是这么简单的了
例子都是修改官方的 上去直接修改就好
至于怎么修改得到什么 oneAry,towAry 请各位各显神通就好
这里只记录基点
就是被官方文档耽误了点时间