vue3中el-table實(shí)現(xiàn)表格合計(jì)行的示例代碼
el-table標(biāo)簽上加屬性 show-summary :summary-method=“getSummary”
<el-table :data="formDate.scoreList" style="width:100%;height: 96%;" stripe show-summary
:summary-method="calculateSummary" :header-cell-style="{ textAlign: 'center', borderColor: ' #CCC', background: '#f5f7fa' }"
:cell-style="{ textAlign: 'center' }">
<el-table-column type="index" label="序號(hào)" width="120"></el-table-column>
<el-table-column type="puuid" label="uuid" v-if="false"></el-table-column>
</el-table>js中添加函數(shù)(合計(jì)沒(méi)有額外的附件參數(shù)添加)
// 合計(jì)
const calculateSummary = ({ columns, data }) => {
const sums = []
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合計(jì)總分'
return
}
const values = data.map((item) => Number(item[column.property]))
// index === 3判斷那一列求合計(jì),下標(biāo)從0開(kāi)始
if (!values.every((value) => Number.isNaN(value)) && index === 3) {
sums[index] =` ${values.reduce((prev, curr) => {
const value = Number(curr)
if (!Number.isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)}`
}
})
return sums
}js中添加函數(shù)(合計(jì)有額外的附件參數(shù)添加的情況)
let activeList=ref('')
// 合計(jì)
const calculateSummary = ({ columns, data }) => {
const sums = []
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合計(jì)總分'
return
}
// 通過(guò)自定義參數(shù)判斷除了表格中的數(shù)據(jù)外還額外加值
let a = activeList.value == 'first' ? 21 : activeList.value == 'second' ? 12 : activeList.value == 'third' ? 18 : 3
// 獲取表格中的數(shù)據(jù)
const values = data.map((item) => Number(item[column.property]))
//index === 3判斷那一列求合計(jì),下標(biāo)從0開(kāi)始
if (!values.every((value) => Number.isNaN(value)) && index === 3) {
// 通過(guò)計(jì)算額外值a+表格中的合計(jì)值(模板字符串無(wú)法直接相加需要轉(zhuǎn)換數(shù)據(jù)格式)
sums[index] = a+Number(` ${values.reduce((prev, curr) => {
const value = Number(curr)
if (!Number.isNaN(value)) {
return prev + curr
} else {
return prev
}
}, 0)}`)
}
})
return sums
}到此這篇關(guān)于vue3中el-table實(shí)現(xiàn)表格合計(jì)行的文章就介紹到這了,更多相關(guān)vue3 el-table合計(jì)行內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Vue3中el-table表格數(shù)據(jù)不顯示的原因和解決方法
- 解決vue3中from表單嵌套el-table時(shí)填充el-input,v-model不唯一問(wèn)題
- vue3插槽:el-table表頭插入tooltip及更換表格背景色方式
- vue3使用element-plus中el-table組件報(bào)錯(cuò)關(guān)鍵字'emitsOptions'與'insertBefore'分析
- vue3?el-table結(jié)合seamless-scroll實(shí)現(xiàn)表格數(shù)據(jù)滾動(dòng)的思路詳解
- vue3+el-table實(shí)現(xiàn)行列轉(zhuǎn)換
相關(guān)文章
深入講解Vue中數(shù)據(jù)代理的工作原理與實(shí)際應(yīng)用
在學(xué)習(xí) Vue 框架的過(guò)程中,數(shù)據(jù)代理(Data Proxy) 是一個(gè)非常核心且重要的概念,本文將結(jié)合代碼示例和調(diào)試截圖,深入講解 Vue 中數(shù)據(jù)代理的工作原理與實(shí)際應(yīng)用,希望對(duì)大家有所幫助2026-01-01
如何在Vue3中創(chuàng)建動(dòng)態(tài)主題切換功能
在Vue3中實(shí)現(xiàn)動(dòng)態(tài)主題切換功能,通過(guò)明亮和暗色主題的選擇,提供個(gè)性化使用體驗(yàn),使用setup語(yǔ)法糖優(yōu)化代碼,通過(guò)創(chuàng)建組件和響應(yīng)式變量來(lái)進(jìn)行主題切換,并動(dòng)態(tài)加載CSS文件2024-09-09
Vue數(shù)組中出現(xiàn)__ob__:Observer無(wú)法取值問(wèn)題的解決方法
__ob__: Observer這個(gè)屬性其實(shí)是Vue監(jiān)控變量產(chǎn)生的,下面這篇文章主要給大家介紹了關(guān)于Vue數(shù)組中出現(xiàn)__ob__:?Observer無(wú)法取值問(wèn)題的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-03-03
深入淺出 Vue 系列 -- 數(shù)據(jù)劫持實(shí)現(xiàn)原理
深入淺出 Vue 系列 -- 數(shù)據(jù)劫持實(shí)現(xiàn)原理2019-04-04
vue3+Element?Plus?v-model實(shí)現(xiàn)父子組件數(shù)據(jù)同步的案例代碼
這篇文章主要介紹了vue3+Element?Plus?v-model實(shí)現(xiàn)父子組件數(shù)據(jù)同步,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2024-01-01
ant-design-vue前端UI庫(kù),如何解決Table中時(shí)間格式化問(wèn)題
這篇文章主要介紹了ant-design-vue前端UI庫(kù),如何解決Table中時(shí)間格式化問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03

