当前位置:网站首页>Using span method to realize row merging of multi-layer table data
Using span method to realize row merging of multi-layer table data
2022-06-22 20:12:00 【SunFlower914】
Recently, I have worked on many projects that require me to table Data needs to be consolidated , I have the honor to read the methods written by my colleagues , How to say, there are all kinds of , But it's complicated , Let's summarize a simple method :
1️⃣ First of all, let's show the effect diagram of the implementation ( The data is found on the Internet ):

2️⃣ structural analysis :
The row union function of the first two columns = The number of corresponding subclass names
The third column type merges rows = The number of subclass names corresponding to the type
3️⃣ Data source presentation :
// Simulated background data
getData () {
this.tableData = [
{
id: 1,
region: ' China ',
type: [
{
sortName: ' apparatus ',
sortList: [
{
name: ' apparatus 1'
},
{
name: ' apparatus 2'
}]},
{
sortName: ' Software ',
sortList: [
{
name: ' Software 1'
},
{
name: ' Software 2'
},
{
name: ' Software 3'
}
]}]},
{
id: 2,
region: ' The United States ',
type: [
{
sortName: ' apparatus ',
sortList: [
{
name: ' apparatus 1'
},
{
name: ' apparatus 2'
}]},
{
sortName: ' Software ',
sortList: [
{
name: ' Software 1'
},
{
name: ' Software 2'
}]}]}]
this.changeData()
},4️⃣ Page structure display
<el-table :data="newTableData" border :span-method = "spanMethod">
<el-table-column prop="id" label="ID"></el-table-column>
<el-table-column prop="region" label=" regional "></el-table-column>
<el-table-column prop="sortName" label=" type "></el-table-column>
<el-table-column prop="name" label=" Subclass name "></el-table-column>
</el-table>5️⃣ Convert table data codes :
// Convert to tabular data
changeData () {
let k = 0 //k Namely newTableData The data source has idIndex The subscript position of the data
this.tableData.forEach(item => {
let count = 0
if (item.type && item.type.length) {
item.type.forEach(typeItem => {
if (typeItem.sortList && typeItem.sortList.length) {
typeItem.sortList.forEach((nameItem, nameIndex) => {
let obj = {
id: item.id,
region: item.region,
sortName: typeItem.sortName,
name: nameItem.name
}
// The first 3 Number of rows merged by column type === Number of subclasses
if (nameIndex === 0) {
obj.nameIndex = typeItem.sortList.length
// id Number of rows merged with the region column === type All of them name length
count += typeItem.sortList.length
}
this.newTableData.push(obj)
})
}
})
}
// 1. tableData There are two rows of data below , First traversal count by 5( In each object name The number of ),k by 0
// 2. to tableData Of the 0 Place plus id Merge row data
// 3. In the second traversal ,count by 4,k by 5, That is to say tableData Of the 5 Place plus id Merge row data
this.newTableData[k].idIndex = count
k += count
})
console.log(this.newTableData, 'this.newTableData')
},6️⃣ How to merge cells :
// merge cell
spanMethod ({ row, column, rowIndex, columnIndex }) {
// If it is the first two columns , Just use idIndex Data to merge
if (columnIndex === 0 || columnIndex === 1) {
if (row.idIndex) {
return [row.idIndex, 1]
} else {
return [0, 0]
}
}
// If it is the third column , Just use nameIndex Data to merge
if (columnIndex === 2) {
if (row.nameIndex) {
return [row.nameIndex, 1]
} else {
return [0, 0]
}
}
}边栏推荐
- 51万奖池邀你参战!第二届阿里云ECS CloudBuild开发者大赛来袭
- 金鱼哥RHCA回忆录:DO447管理用户和团队的访问--创建和管理Ansible Tower用户
- [in depth understanding of tcaplus DB technology] getting started tcaplus SQL driver
- [deeply understand tcapulusdb technology] tcapulusdb table management - delete table
- Matplotlib set axis scale interval
- 【深入理解TcaplusDB技术】TcaplusDB 表管理——清理表
- [in depth understanding of tcapulusdb technology] tcapulusdb model
- Summer Challenge [FFH] Hongmeng machine learning journey from scratch NLP emotion analysis
- 数字经济加速落地,能为中小企业带来什么?
- Assign values to objects
猜你喜欢
![[deeply understand tcapulusdb technology] tcapulusdb table management - clean up table](/img/2b/3ab5e247ac103728b4d3579c3c5468.png)
[deeply understand tcapulusdb technology] tcapulusdb table management - clean up table

【深入理解TcaplusDB技术】TcaplusDB 表管理——清理表

如何低成本快速搭建企业知识库?

不断重修的计划与变化

【深入理解TcaplusDB技术】入门Tcaplus SQL Driver

client-go gin的简单整合十一-Delete

iVX无代码挑战五秒游戏制作
2019 年总结:31岁,不过是另一个开始

年中大促 | 集成无忧,超值套餐 6 折起
![[deeply understand tcapulusdb technology] view the online operation of tcapulusdb](/img/6f/2d62030e631e3085acf72951f2416f.png)
[deeply understand tcapulusdb technology] view the online operation of tcapulusdb
随机推荐
Async-profiler介绍
Recv function with timeout
【深入理解TcaplusDB技术】TcaplusDB运维单据
Georgia Institute of technology - coordinated coverage and tracking planning of multi UAV wildfire with service quality assurance
带超时的recv函数
Assign values to objects
【深入理解TcaplusDB技术】查看TcaplusDB线上运行情况
[in depth understanding of tcaplus DB technology] Introduction to tcaplus JDBC development
Heap sort (principle plus code)
B tree code (C language)
Google | ICML 2022: sparse training status in deep reinforcement learning
【深入理解TcaplusDB技术】入门Tcaplus-JDBC开发
拓扑排序
[compréhension approfondie de la base de connaissances tcaplusdb] déploiement de la version locale de tcaplusdb FAQ
[deeply understand tcapulusdb technology] how to initialize and launch tcapulusdb machine
[in depth understanding of tcapulusdb technology] business guide for creating doc acceptance
R语言数据预处理、把类型变量转化为因子变量,把数据集转化为h2o格式、数据集划分(训练集、测试集、验证集)
web技术分享| 【高德地图】实现自定义的轨迹回放
【深入理解TcaplusDB技术】TcaplusDB事务管理——错误排查
An error is reported when idea writes JSP code, but it is solved by normal operation