el-table合并指定列内容相同的行 一共七列合并前五列
时间: 2023-11-29 08:47:02 浏览: 107
Table相同行合并,数量汇总
以下是el-table合并指定列内容相同的行,一共七列合并前五列的代码实现:
```javascript
<template>
<el-table :data="tableData" border>
<el-table-column prop="name" label="姓名" :rowspan="2"></el-table-column>
<el-table-column prop="age" label="年龄" :rowspan="2"></el-table-column>
<el-table-column prop="address" label="地址" :rowspan="2"></el-table-column>
<el-table-column label="其他信息" :colspan="4"></el-table-column>
<el-table-column prop="date" label="日期" :rowspan="2"></el-table-column>
<el-table-column prop="amount" label="金额" :rowspan="2"></el-table-column>
<el-table-column prop="status" label="状态" :rowspan="2"></el-table-column>
<el-table-column prop="remark" label="备注" :rowspan="2"></el-table-column>
<el-table-column prop="other1" label="其他1"></el-table-column>
<el-table-column prop="other2" label="其他2"></el-table-column>
<el-table-column prop="other3" label="其他3"></el-table-column>
<el-table-column prop="other4" label="其他4"></el-table-column>
</el-table>
</template>
<script>
export default {
data() {
return {
tableData: [
{
name: '张三',
age: 18,
address: '北京市',
other1: '其他1',
other2: '其他2',
other3: '其他3',
other4: '其他4',
date: '2021-01-01',
amount: 100,
status: '已完成',
remark: '备注1'
},
{
name: '李四',
age: 20,
address: '上海市',
other1: '其他1',
other2: '其他2',
other3: '其他3',
other4: '其他4',
date: '2021-01-02',
amount: 200,
status: '已完成',
remark: '备注2'
},
{
name: '王五',
age: 22,
address: '广州市',
other1: '其他1',
other2: '其他2',
other3: '其他3',
other4: '其他4',
date: '2021-01-03',
amount: 300,
status: '已完成',
remark: '备注3'
},
{
name: '赵六',
age: 24,
address: '深圳市',
other1: '其他1',
other2: '其他2',
other3: '其他3',
other4: '其他4',
date: '2021-01-04',
amount: 400,
status: '已完成',
remark: '备注4'
},
{
name: '小明',
age: 26,
address: '北京市',
other1: '其他1',
other2: '其他2',
other3: '其他3',
other4: '其他4',
date: '2021-01-05',
amount: 500,
status: '已完成',
remark: '备注5'
},
{
name: '小红',
age: 28,
address: '上海市',
other1: '其他1',
other2: '其他2',
other3: '其他3',
other4: '其他4',
date: '2021-01-06',
amount: 600,
status: '已完成',
remark: '备注6'
},
{
name: '小刚',
age: 30,
address: '广州市',
other1: '其他1',
other2: '其他2',
other3: '其他3',
other4: '其他4',
date: '2021-01-07',
amount: 700,
status: '已完成',
remark: '备注7'
}
]
}
},
methods: {
mergeCell({ row, column, rowIndex, columnIndex }) {
if (columnIndex < 5) {
let rowspan = 1
for (let i = rowIndex + 1; i < this.tableData.length; i++) {
if (this.tableData[i][column.prop] === row[column.prop]) {
rowspan++
} else {
break
}
}
if (rowspan > 1) {
return {
rowspan,
colspan: 1
}
} else {
return {
rowspan: 0,
colspan: 0
}
}
}
}
}
}
</script>
```
阅读全文