vue + element el-table 合并行(自用)
html:<el-table id="out-table" :data="tableData" border :span-method="objectSpanMethod">js:methods内代码:getListDataForRowAndColumn(data){let self = this;self.rowAnd...
·
html:
<el-table id="out-table" :data="tableData" border :span-method="objectSpanMethod">
js:
methods内代码:
getListDataForRowAndColumn(data){
let self = this;
self.rowAndColumn = [];
self.rowRoomColumn = [];
for (var i = 0; i < data.length; i++) {
if (i === 0) {
// 如果是第一条记录(即索引是0的时候),向数组中加入1
self.rowAndColumn.push(1);
self.pos = 0;
self.rowRoomColumn.push(1);
self.posT = 0;
} else {
if (data[i].storeName === data[i - 1].storeName) {
// 如果storeName相等就累加,并且push 0
self.rowAndColumn[self.pos] += 1
self.rowAndColumn.push(0)
if (data[i].roomName === data[i - 1].roomName) {
// 如果roomName相等就累加,并且push 0
self.rowRoomColumn[self.posT] += 1
self.rowRoomColumn.push(0)
}else{
self.rowRoomColumn.push(1)
self.posT = i
}
} else {
// 不相等push 1
self.rowAndColumn.push(1)
self.pos = i;
self.rowRoomColumn.push(1)
self.posT = i
}
}
}
},
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
let self = this
if (columnIndex === 0) {
if (self.rowAndColumn[rowIndex]) {
let rowNum = self.rowAndColumn[rowIndex];
return {
rowspan: rowNum,
colspan: rowNum > 0 ? 1 : 0
}
}
return {
rowspan: 0,
colspan: 0
}
}
if (columnIndex === 1) {
if (self.rowRoomColumn[rowIndex]) {
let roomNum = self.rowRoomColumn[rowIndex];
return {
rowspan: roomNum,
colspan: roomNum > 0 ? 1 : 0
}
}
return {
rowspan: 0,
colspan: 0
}
}
},
更多推荐
已为社区贡献2条内容
所有评论(0)