Vue+el-table realizes merging cells

Vue+el-table realizes merging cells

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:
  • Vue dynamically merges cells and adds subtotals function example
  • Implementation of merging multiple columns of Vue cells
  • Antd vue table merges cells across rows and customizes content instances
  • In vue, elment-ui table merges the same data cells in the upper and lower rows

<<:  Knowledge about MySQL Memory storage engine

>>:  The concept of MTR in MySQL

Recommend

Learn the operating mechanism of jsBridge in one article

Table of contents js calling method Android 1.js ...

Vue uses canvas to realize image compression upload

This article shares the specific code of Vue usin...

Detailed explanation of how to use WeChat mini program map

This article example shares the specific implemen...

Writing a web calculator using javascript

This article mainly records the effect of using j...

Detailed analysis of mysql MDL metadata lock

Preface: When you execute a SQL statement in MySQ...

Detailed explanation of triangle drawing and clever application examples in CSS

lead Some common triangles on web pages can be dr...

Timeline implementation method based on ccs3

In web projects we often use the timeline control...

Detailed steps for Spring Boot packaging and uploading to Docker repository

Important note: Before studying this article, you...

JavaScript to implement a simple shopping form

This article shares the specific code of JavaScri...

Deploy the Vue project on a Linux server

Case 1 vue-cli builds the vue3 project, uploads t...

Realize map aggregation and scattering effects based on vue+openlayer

Table of contents Preface: Result: 1. Polymerizat...

The role of nextTick in Vue and several simple usage scenarios

Purpose Understand the role of nextTick and sever...

Vue implements the right slide-out layer animation

This article example shares the specific code of ...

JavaScript plugin encapsulation for table switching

This article shares the encapsulation code of Jav...