el-table增加两条合计项目

今天需求中有一条要求使用table表格要有两条合计项,要求实现效果:

主要代码:

summaryMethod(param) {
          const { columns, data } = param
          const sums = []
          columns.forEach((column, index) => {
            if (index === 0) {
              const el = <p>合计:<br/><br/>总计:</p> // 主要代码
              sums[index] = el
              return
            }
            if (column.property == 'budgerAllPrice') { // 如果el-table-column中没有prop属性,这里的column.property是undefined,所以判断一下values数组是否为空
              const values = data.map((item) => {
                return Number(item.budgerAllPrice)
              })// 把对应一列中的之全部取出,放到一个数组中
              if (!values.every(value => isNaN(value))) {
                let itemPrice = 0
                sums[index] = values.reduce((prev, curr) => {
                  const value = Number(curr)// 将values中的每个值转换为number类型
                  if (!isNaN(value)) {
                    itemPrice += Number(curr)
                      // this.tableData.goodstotal + this.tableData.accessorytotal + this.tableData.optiontotal
                    const pel = <p>¥{this.$options.filters['money'](itemPrice)}元<br/><br/>¥{this.$options.filters['money'](vm.totalPrice)}元</p> // 主要代码
                    return pel
                  } else {
                    return this.$options.filters['money'](prev)
                  }
                }, 0)
              } else {
                sums[index] = '无'
              }
            }
          })
          return sums
        },

其中table表格需要绑定:summary-method="summaryMethod",这里可以参考ElementUI官方文档https://element.eleme.cn/#/zh-CN/component/table

主要是记录一下elementUI中部常用的属性,以防自己忘记

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值