计算table列表中某一列字段的所有行数据的累计和

在计算属性中,使用 reduce 方法计算table列表中某一列字段的所有行数据的累计和

    computed: {
      sumHjql(){  //多选合计气量
        return  this.dxhjql = this.noticeBillList.map(item=>item.ql + item.hjql).reduce(
          (acc, cur) => (parseFloat(cur) + acc), 0)
      },
        this.selectionQl = this.noticeBillList.map(item=>item.hjql).reduce(
          (acc, cur) => (parseFloat(cur) + acc), 0)
    },
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 element-ui 的 el-table 组件合计某一列可以通过以下步骤实现: 1. 给表格数据源添加一个合计字段,用来存储该的总和。 2. 在 el-table-column 组件使用 scoped-slot 自定义的内容,将该的每个单元格的值累加到合计字段。 3. 在表格底部添加一个 el-table-footer 组件,显示合计字段的值。 下面是一个简单的示例代码: ```html <template> <el-table :data="tableData"> <el-table-column prop="name" label="姓名"></el-table-column> <el-table-column prop="age" label="年龄"> <template slot-scope="scope">{{ scope.row.age }}</template> </el-table-column> <el-table-column prop="score" label="分数"> <template slot-scope="scope"> {{ scope.row.score }} <!-- 将该的每个单元格的值累加到合计字段 --> <span hidden>{{ total += scope.row.score }}</span> </template> </el-table-column> <el-table-footer> <template slot="footer"> <!-- 显示合计字段的值 --> <el-table-column :label="'合计:' + total"></el-table-column> </template> </el-table-footer> </el-table> </template> <script> export default { data() { return { tableData: [ { name: '张三', age: 20, score: 80 }, { name: '李四', age: 22, score: 90 }, { name: '王五', age: 21, score: 85 } ], total: 0 // 合计字段 }; } }; </script> ``` 在上面的示例代码,我们使用了一个隐藏的 span 元素来实现将该的每个单元格的值累加到合计字段。同时,我们使用了 el-table-footer 组件来显示合计字段的值。 需要注意的是,如果表格有分页的话,以上方法只能计算当前页的合计值。如果需要计算所有数据的合计值,需要在后台进统计。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值