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

Example of how to generate random numbers and concatenate strings in MySQL

This article uses an example to describe how MySQ...

Detailed explanation of Grid layout and Flex layout of display in CSS3

Gird layout has some similarities with Flex layou...

Detailed explanation of custom swiper component in JavaScript

Table of contents Effect display Component Settin...

How to configure MySQL master-slave replication under Windows

MySQL master-slave replication allows data from o...

A brief understanding of the differences between MySQL InnoDB and MyISAM

Preface MySQL supports many types of tables (i.e....

About the garbled problem caused by HTML encoding

Today a junior student asked a question. The HTML...

Implementation method of Mysql tree recursive query

Preface For tree-structured data in the database,...

Summary of data interaction between Docker container and host

Preface When using Docker in a production environ...

A detailed analysis and processing of MySQL alarms

Recently, a service has an alarm, which has made ...

VMware Workstation installation Linux (Ubuntu) system

For those who don't know how to install the s...

Several ways to solve the 1px border problem on mobile devices (5 methods)

This article introduces 5 ways to solve the 1px b...

mysql5.6.zip format compressed version installation graphic tutorial

Preface: MySQL is a relational database managemen...

Hexadecimal color codes (full)

Red and pink, and their hexadecimal codes. #99003...

Learn asynchronous programming in nodejs in one article

Table of Contents Introduction Synchronous Asynch...