• element-UI动态渲染表格时相同数据表格合并,比如日期等数据相同的地方合并单元格,具体看代码


        <el-table :data="tableDataArr" :span-method="cellMerge" style=" 100%;display:inline-block;">
              <el-table-column prop="stat_date" sortable label="日期" width="120"></el-table-column>
            <el-table-column  prop="request_uri" label="URL" width="700"></el-table-column>
            <el-table-column prop="total" sortable label="total" width="320"></el-table-column>
          </el-table>



    data():{
    return{
      tableDataArr: [],//存放表格数据
          spanArr: [],//二维数组,用于存放单元格合并规则
          position: 0,//用于存储相同项的开始index
    }
    }
    methods:{
    getData(){
    this.rowspan(0,'stat_date');
    this.rowspan(1,'request_uri'); 
    this.rowspan(2,'total');
    }
    rowspan(idx, prop) {
          this.spanArr[idx] = [];
          this.position = 0; 
          this.tableDataArr.forEach((item,index) => {
            if( index === 0){
              this.spanArr[idx].push(1);
              this.position = 0;
            }else{
              if(this.tableDataArr[index][prop] === this.tableDataArr[index-1][prop] ){
                this.spanArr[idx][this.position] += 1;//有相同项
                this.spanArr[idx].push(0); // 名称相同后往数组里面加一项0
              }else{
                this.spanArr[idx].push(1);//同列的前后两行单元格不相同
                this.position = index;
              }
            }
          })
        },
        //表格单元格合并
        cellMerge({ row, column, rowIndex, columnIndex }) {
          for(let i = 0; i<this.spanArr.length; i++) {
            if(columnIndex === i){
              const _row = this.spanArr[i][rowIndex];
              const _col = _row>0 ? 1 : 0;
              // console.log('第'+rowIndex+'行','第'+i+'列','rowspan:'+_row,'colspan:'+_col)
              return {
                rowspan: _row,
                colspan: _col
              }
            }
          }
        }
    }

      

  • 相关阅读:
    elselect下拉数据过多解决办法
    移动端开发遇到的问题汇总
    win7系统可关闭的服务
    安装Qcreator2.5 + Qt4.8.2 + MinGW_gcc_4.4 (win7环境)
    学习Qt的资源
    c++学习 定位new表达式
    eltablecolumn中添加echarts
    js对象数组封装,形成表格,并在表格中添加echarts直折线图
    Unity学习笔记3:随机数和动画脚本
    关于Unity的一些概念和语法
  • 原文地址:https://www.cnblogs.com/bigkuan/p/13900942.html
Copyright © 2020-2023  润新知