zoukankan      html  css  js  c++  java
  • elementUI合并单元格

    <el-table :data="tableDataFormat" border :header-cell-style="{background:'#FAFAFA'}" :span-method="arraySpanMethod" :row-class-name="rowClassName" @cell-mouse-enter="handleMouseEnter" @cell-mouse-leave="handleMouseLeave">
     
     
    data(){
        return {
          spanArr:[],
          tableData:[], //元数据
          tableDataFormat:[],//format后的数据
          cellIndex: -1,
        }
      },
     
     
    // 鼠标进入单元格
        handleMouseEnter(row, column, cell, event) {
          this.tableDataFormat.forEach((item) => {
            // console.log(row.order,item.order)
            if (row.order === item.order) {
              this.cellIndex = row.order;
            }
          })
        },
        // 给相应的rowIndex添加类名
        rowClassName({ row, rowIndex }) {
            let r = -1;
            this.tableDataFormat.forEach((item) => {
              if (this.cellIndex === row.order) {
                r = rowIndex;
              }
            });
            if (rowIndex === r) {
              return 'hover-row';
            }
          },
          // 鼠标离开
        handleMouseLeave(row, column, cell, event) {
          this.cellIndex = -1;
        },
        arraySpanMethod({ row, column, rowIndex, columnIndex }) {
          if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2 || columnIndex === 3 || columnIndex === 4  || columnIndex === 9) {
              const _row = this.spanArr[rowIndex];
              const _col = _row > 0 ? 1 : 0;
              // console.log(`rowspan:${_row} colspan:${_col}`)
              return { // [0,0] 表示这一行不显示, [2,1]表示行的合并数
                    rowspan: _row,
                    colspan: _col
              }
            }
          },
        getSpanArr(data) { 
            for (var i = 0; i < data.length; i++) {
              if (i === 0) {
                this.spanArr.push(1);
                this.pos = 0
              } else {
                // 判断当前元素与上一个元素是否相同
              if (data[i].strategy_id === data[i - 1].strategy_id) {
                  this.spanArr[this.pos] += 1;
                  this.spanArr.push(0);
                } else {
                  this.spanArr.push(1);
                  this.pos = i;
                }
              }
              // console.log(this.spanArr)
          }
        },
  • 相关阅读:
    C++字符串转数字,数字转字符串
    [转]基础知识整理
    POJ 3071 Football
    POJ 3744 Scout YYF I
    2013成都Regional:一块木板,几个气球
    HDOJ 4497 GCD and LCM
    POJ 1185 炮兵阵地
    POJ 2031 Building a Space Station
    HDOJ 4717 The Moving Points
    CSU 1328: 近似回文词
  • 原文地址:https://www.cnblogs.com/cuikaitong/p/12835847.html
Copyright © 2011-2022 走看看