objectSpanMethod定义该方法,在el-table的表头中
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
//表格合并行,这里表是合并了第三列之后的
if (columnIndex >=2 ) {
const _row = this.spanArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col
};
}
},
合并行的数组
rowspan() {
this.spanArr=[]
//获取该页的分页信息,如果在服务端进行分页则不需要这行代码
var list=this.tableData.slice((this.currentPage-1)*this.pageSize,this.currentPage*this.pageSize)
list.forEach((item, index) => {
if (index === 0) {
this.spanArr.push(1);
this.position = 0;
} else {
if ((list[index].qxdh === list[index - 1].qxdh) && list[index].qxdh!==null ) {
this.spanArr[this.position] += 1;
this.spanArr.push(0);
} else {
this.spanArr.push(1);
this.position = index;
}
}
});
},
注意:如果是在服务端分页好了则不需要以下的操作,以下的操作是获取所有的数据在前端进行分页。
//每次翻页都会重新获取合并的数组行
handleSizeChange: function handleSizeChange(val) {
this.pageSize = val;
this.rowspan()
},
handleCurrentChange: function handleCurrentChange(val) {
this.currentPage = val;
this.rowspan()
},