Element-table表格末尾按指定列合计的实现方法

getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 1) {
          sums[index] = '合计'
          return
        }
        const values = data.map(item => Number(item[column.property]))
        console.log(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)
      //通过column.property指定列
switch(column.property){ case 'product_count': sums[index] = toThousandslsFilter(sums[index]) break; case 'sum': sums[index] = toThousandslsFilter(sums[index]) break; default: sums[index] = '' } } else { sums[index] = '' } }) return [sums] }

 

posted @ 2023-06-26 15:47  野望之风  阅读(390)  评论(0编辑  收藏  举报