vue elementUI中的table合计指定列求和

注意点:

  1. 中 加show-summary和:summary-method=“getSummaries”

  2. 中要加 prop

 getSummaries (param) {
  const { columns, data } = param
  const sums = []
  columns.forEach((column, index) => {
  if (index === 0) {
   sums[index] = '总计'
  } else if (index === 5 || index === 6) {
   const values = data.map(item => 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)
   } else {
   sums[index] = 'N/A'
   }
  } else {
   sums[index] = '--'
  }
  })
  return sums
 }

你可能感兴趣的:(前端,elementUI,vue,vue.js,elementui,前端)