element合并最后一列的所有行

1 篇文章 0 订阅

element合并最后一列的所有行

页面

     <el-table
      :data="dataTable"
      :span-method="objectSpanMethod"
      v-loading='loading'
      border
      stripe
      style="width: 100%">
        <el-table-column prop="name" label="区域"> </el-table-column>
        <el-table-column prop="capacity" label="容量(MW)"> </el-table-column>
        <el-table-column prop="speed" label="风速(m/s)"> </el-table-column>
        <el-table-column prop="power" label="功率(kW)"> </el-table-column>
        <el-table-column prop="" label="运行中/容量(MW)">
          <template slot-scope="scope">
            <div>{{ scope.row.runNumber + '/' + scope.row.runCapacity }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="" label="停机中/容量(MW)">
          <template slot-scope="scope">
            <div>{{ scope.row.stopNumber + '/' + scope.row.stopCapacity }}</div>
          </template></el-table-column>
        <el-table-column prop="" label="故障中/容量(MW)">
          <template slot-scope="scope">
            <div>{{ scope.row.runFaultNumber + scope.row.stopFaultNumber + '/' + scope.row.runFaultCapacity + scope.row.stopFaultCapacity }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="energy" label="当年发电量(万kWh)">
        </el-table-column>
        <el-table-column prop="updatedAt" label="更新时间">
        </el-table-column>
      </el-table>

数据

 data() {
    return {
      timer: '',
      dataTable: [],
      spanArr: [],
      pos: 0,
      loading: false,
    };
  },

数据处理

        //增加最后一行合计/平均
        let lastLine = {
          name: '合计/平均',
          power: 0,
          energy: 0,
          capacity: 0,
          runCapacity: 0,
          runFaultCapacity: 0,
          runFaultNumber: 0,
          runNumber: 0,
          speed: 0,
          stopCapacity: 0,
          stopFaultCapacity: 0,
          stopFaultNumber: 0,
          stopNumber: 0,
          updatedAt: ''
        }
        //合并最后一列所有行
        //解析dataTable格式,新增一列隐藏列,计算更新时间列每次要合并的行数(以本例中所有table的第一行updatedAt均有数据为前提)
        /* 图审分析合并列---计算每次合并行数(此合并列中,有两列合并,pos合并空白行,pos2合并除第一行的所有行) */
        for (var i = 0; i < this.dataTable.length; i++) {
          this.dataTable[i].updatedAt = dateFormat("mm-dd HH:MM", this.dataTable[i].updatedAt)
          
          lastLine.power += this.dataTable[i].power
          lastLine.energy += this.dataTable[i].energy
          lastLine.capacity += this.dataTable[i].capacity
          lastLine.runCapacity += this.dataTable[i].runCapacity
          lastLine.runFaultCapacity += this.dataTable[i].runFaultCapacity
          lastLine.runFaultNumber += this.dataTable[i].runFaultNumber
          lastLine.runNumber += this.dataTable[i].runNumber
          lastLine.stopCapacity += this.dataTable[i].stopCapacity
          lastLine.stopFaultCapacity += this.dataTable[i].stopFaultCapacity
          lastLine.stopFaultNumber += this.dataTable[i].stopFaultNumber
          lastLine.stopNumber += this.dataTable[i].stopNumber
          lastLine.speed += this.dataTable[i].speed


          this.dataTable[i].energy = (this.dataTable[i].energy/10000).toFixed(2)
          if (i === 0) {
            this.spanArr.push(1);//第一行updatedAt均有数据,记录当前合并行数为1.
            this.pos = 0;//spanArr的当前索引是0,已存进一条数据
          } else {
            // 判断当前元素与上一个元素是否相同,或者为空
            if (this.dataTable[i].updatedAt === this.dataTable[i - 1].updatedAt || this.dataTable[i].updatedAt === "") {
              this.spanArr[this.pos] += 1;
              this.spanArr.push(0);
            } else {
              this.spanArr.push(1);
              this.pos = i;
            }
          }
        }
        // 在合并总和/平均单元格
        this.spanArr[this.pos] += 1;
        lastLine.speed = lastLine.speed / this.dataTable.length
        lastLine.energy = (lastLine.energy/10000).toFixed(2)
        lastLine.updatedAt = this.dataTable[0].updatedAt
        this.dataTable.push(lastLine)

方法

    // 合并列 
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 8) {
        const _row = this.spanArr[rowIndex];
        const _col = _row > 0 ? 1 : 0;
        return {
          rowspan: _row,
          colspan: _col
        }
      }
    },

实现效果

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值