el-table 表单合并逻辑简化版

73 阅读1分钟

开发中经常会用到表格合并,我在这里简单记录一下代码;

` // 单独处理一下合并

calculateSpans() {
// 只保留第一个的数据
this.classtableData.forEach((item, index) => {
let filterlsit = this.classtableData.filter(ite => ite['岗位'] == item['岗位'])
item.rownums = filterlsit.length;
let findIndexnums = this.classtableData.findIndex(ite => ite['岗位'] == item['岗位'])
if (index > findIndexnums) {
        item.rownums = 0
}
})
},



// 饿了么组件合并代码逻辑

objectSpanMethod({
	row,
	column,
	rowIndex,
	columnIndex
}) {
        if (column.property === '岗位') {
                return {
		rowspan: row.rownums,
		colspan: row.rownums ? 1 : 0
                };
        } else if (column.property === '得分汇总') {
                return {
		rowspan: row.rownums,
		colspan: row.rownums ? 1 : 0
                };
        } else {
              return {
		rowspan: 1,
		colspan: 1
                };
        }
},

`

首先先处理一下数组,尽量叫后端传正确的顺序,不传就友好交流(ma si ta)。