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

How to use MySQL 5.7 temporary tablespace to avoid pitfalls

Introduction MySQL 5.7 aims to be the most secure...

Website background music implementation method

For individual webmasters, how to make their websi...

Example of implementing translation effect (transfrom: translate) with CSS3

We use the translate parameter to achieve movemen...

28 Famous Blog Redesign Examples

1. WebDesignerWall 2. Veerle's Blog 3. Tutori...

mysql trigger creation and usage examples

Table of contents What is a trigger Create a trig...

Install Docker for Windows on Windows 10 Home Edition

0. Background Hardware: Xiaomi Notebook Air 13/In...

The principle and implementation of two-way binding in Vue2.x

Table of contents 1. Implementation process 2. Di...

Solution to Mysql binlog log file being too large

Table of contents 1. Related binlog configuration...

Web Design Tutorial (4): About Materials and Expressions

<br />Previous Web Design Tutorial: Web Desi...