This article example shares the specific code of el-table to realize the merging of cells for your reference. The specific content is as follows el-table merge cells (vue+element) - First put in el-table: span-method="arraySpanMethod" <el-table :header-cell-style="{background:'#eef1f6',color:'#606266'}" :data="merchantList" border :span-method="arraySpanMethod"> <el-table-column align="center" prop="provinceName" label="Province"> </el-table-column> <el-table-column align="center" label="Agent Name"> <template scope="scope"> <span>{{scope.row.parentMerchantName == scope.row.merchantName ? '---' : scope.row.parentMerchantName}}</span> </template> </el-table-column> <el-table-column align="center" prop="cityName" label="市"> </el-table-column> <el-table-column align="center" prop="countryName" label="区"> </el-table-column> <el-table-column align="center" prop="merchantName" label="店铺"> </el-table-column> </el-table> Write the method in methods: //Merge cells arraySpanMethod ({ row, column, rowIndex, columnIndex }) { if (columnIndex === 0) {//Merge method for the first column, province const _row_1 = this.provinceArr[rowIndex]; const _col_1 = _row_1 > 0 ? 1 : 0; //If it is merged, _row=0, then this column needs to be cancelled return { rowspan: _row_1, colspan: _col_1 } } }, // Initialize merageInit () { this.provinceArr = [] this.provincePos = 0 }, //Method of merging arrays merge() { this.merageInit() for (var i = 0; i < this.merchantList.length; i++) { if (i === 0) { //The first line must exist this.provinceArr.push(1) this.provincePos = 0 } else { // Determine whether the current element is the same as the previous element this.provincePos is the serial number of the provinceArr content //province if (this.merchantList[i].provinceName === this.merchantList[i - 1].provinceName) { this.provinceArr[this.provincePos] += 1 this.provinceArr.push(0) } else { this.provinceArr.push(1) this.provincePos = i } } } }, Results: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Knowledge about MySQL Memory storage engine
>>: The concept of MTR in MySQL
Table of contents js calling method Android 1.js ...
This article shares the specific code of Vue usin...
This article example shares the specific implemen...
This article mainly records the effect of using j...
Preface: When you execute a SQL statement in MySQ...
lead Some common triangles on web pages can be dr...
In web projects we often use the timeline control...
Important note: Before studying this article, you...
This article shares the specific code of JavaScri...
Case 1 vue-cli builds the vue3 project, uploads t...
Table of contents Preface: Result: 1. Polymerizat...
Purpose Understand the role of nextTick and sever...
Table of contents Preface 1. Brief Analysis of th...
This article example shares the specific code of ...
This article shares the encapsulation code of Jav...