el-table 底部合计栏的合并计算

el-mentpus有 关于列的合计,缺少行合计的问题,再此总结分享。

模板部分

<template>
show-Summary    //展示底部合计栏
:span-method="spanMethod"    //控制哪一个特定的列不进行计算

方法部分

<script setup>
const getSummaries = (param) => {
  const { columns, data } = param;
  const sums = [];
  columns.forEach((column, index) => {
    if (index === 0) {
      sums[index] = '总价';
      return;
    }
    if (index === 1) {
      sums[index] = '';
      return;
    }         //可以控制特定的列不展示或展示特定的内容
    if (column.property !== 'inoutProjectName') {
      const values = data.map((item, index) => {
        if (index <= data.length-2 && data[index+1].orderInoutProjectId === data[index].orderInoutProjectId && data[index+1][column.property] === data[index][column.property]) {                        
        } else {    // 合并的行正确计算
          return Number(item[column.property])
        }
      });
      if (!values.every(value => isNaN(value))) {
        sums[index] = values.reduce((prev, curr) => {
          const value = Number(curr);
          if (!isNaN(value)) {
            return prev + curr;
          } else {
            return prev;
          }
        }, 0);
        // sums[index] += ' 元';
        // sums[index] += ' ';     //单位名称

      } else {
        sums[index] = '';
      }
    }
  });
  console.log("总和",sums)
  return sums;
}

效果展示

在这里插入图片描述

合计的颜色改变

在样式中加入这段代码

<style scoped>
/*合计字体颜色*/
/deep/ .el-table__footer-wrapper tbody td {
  color: #409EFF;
  cursor: pointer;
}
/deep/ .el-table__footer-wrapper tbody td:first-child{
  color: black;
  cursor: auto;
}
</style>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值