ant-design-vue
customRender: (value, row, index) => {
const obj = {
children: value,
attrs: {}
};
obj.attrs.rowSpan = this.myArray[index];
return obj;
}
func(data) {
var x = "";
var count = 0;
var startindex = 0;
for (var i = 0; i < data.length; i++) {
var val = data[i].schoolId;
if (i == 0) {
x = val;
count = 1;
this.myArray[0] = 1;
} else {
if (val == x) {
count++;
this.myArray[startindex] = count;
this.myArray[i] = 0;
} else {
count = 1;
x = val;
startindex = i;
this.myArray[i] = 1;
}
}
}
}
this.myArray = new Array(this.tableData.length);
this.func(this.tableData);
element-ui
- el-table设置属性 span-method="objectSpanMethod
- 合并行方法
function objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
const _row = this.spanArr[0][rowIndex]
return {
rowspan: _row,
colspan: 1
}
}
}
rowspan (idx, prop) {
this.spanArr[idx] = []
this.position = 0
<!-- 要合并的表格数据 -->
this.tableData.forEach((item, index) => {
if (index === 0) {
this.spanArr[idx].push(1)
this.position = 0
} else {
if (
this.tableData[index]['listenSchoolId'] ===
this.tableData[index - 1]['listenSchoolId']
) {
this.spanArr[idx][this.position] += 1
this.spanArr[idx].push(0)
} else {
this.spanArr[idx].push(1)
this.position = index
}
}
})
}