vue element 表單 使用自定義合計方法 summary-method


判斷不同的id 可進行不同的操作,這邊按自己的需求來

getSummaries(param) {
const { columns, data } = param
const sums = []
columns.forEach((column, index) => {
if (index === 0) { // 只找第一列放合計
sums[index] = '合計:'
return
}
if (column.property === 'name') { // 判斷當前prop綁定的ID
const values = data.map(item => (item[column.property]))// 把對應一列中的之全部取出,放到一個數組中
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr)// 將values中的每個值轉換為number類型
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)
sums[index] += '元'
} else if (column.property === 'text') {
const values = data.map(item => (item[column.property]))// 把對應一列中的之全部取出,放到一個數組中
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr)// 將values中的每個值轉換為number類型
if (!isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)
sums[index] += '人'
}
})
return sums
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM