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ì)沒有額外的附件參數(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開始 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 } // 通過自定義參數(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開始 if (!values.every((value) => Number.isNaN(value)) && index === 3) { // 通過計(jì)算額外值a+表格中的合計(jì)值(模板字符串無法直接相加需要轉(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不唯一問題
- 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 elementUI表格控制顯示隱藏對(duì)應(yīng)列的方法
這篇文章主要為大家詳細(xì)介紹了vue elementUI表格控制顯示隱藏對(duì)應(yīng)列的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04vue項(xiàng)目,代碼提交至碼云,iconfont的用法說明
這篇文章主要介紹了vue項(xiàng)目,代碼提交至碼云,iconfont的用法說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07Vue.js系列之項(xiàng)目結(jié)構(gòu)說明(2)
這篇文章主要介紹了Vue.js系列之項(xiàng)目結(jié)構(gòu)說明(2)的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2017-01-01Vue中失去焦點(diǎn)時(shí)所觸發(fā)的事件問題
這篇文章主要介紹了Vue中失去焦點(diǎn)時(shí)所觸發(fā)的事件問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06vue.js的computed,filter,get,set的用法及區(qū)別詳解
下面小編就為大家分享一篇vue.js的computed,filter,get,set的用法及區(qū)別詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-03-03基于vue實(shí)現(xiàn)頁面滾動(dòng)加載的示例詳解
頁面內(nèi)容太多會(huì)導(dǎo)致加載速度過慢,這時(shí)可考慮使用滾動(dòng)加載即還沒有出現(xiàn)在可視范圍內(nèi)的內(nèi)容塊先不加載,出現(xiàn)后再加載,所以本文給大家介紹了基于vue實(shí)現(xiàn)頁面滾動(dòng)加載的示例,需要的朋友可以參考下2024-01-01