• 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)
          }
        },
  • 相关阅读:
    Fast Search:爬网测试 金大昊(jindahao)
    FAST Search :deployment.xml
    TFS:强制签入已签出的文件 金大昊(jindahao)
    采用权限控制的工作流权限设计 金大昊(jindahao)
    FAST Search :创建自定义属性 金大昊(jindahao)
    SharePoint:替换搜索结果连接URL 金大昊(jindahao)
    SharePoint:迁移
    SharePoint:关于word模板内容类型(template.dotx) 金大昊(jindahao)
    SharePoint:备份和还原
    BCS 爬网报错 金大昊(jindahao)
  • 原文地址:https://www.cnblogs.com/cuikaitong/p/12835847.html
Copyright © 2020-2023  润新知