element的el-table自定義最后一行的實(shí)現(xiàn)代碼
element的el-table自定義最后一行
場(chǎng)景:
最后一行要顯示一些其他結(jié)果,用的是element ui 自帶的數(shù)據(jù)總計(jì)的屬性;返回一個(gè)數(shù)組,會(huì)按下標(biāo)進(jìn)行展示。

代碼:
<el-table
:summary-method="getSummaries"
show-summary
:data="tableData"
stripe
style="width: 50% ;margin-top: 20px;font-size: 15px;">
<el-table-column prop="date" label="日期" width="180">
</el-table-column>
<el-table-column prop="name" label="姓名" width="180">
</el-table-column>
<el-table-column prop="address" label="地址">
</el-table-column>
</el-table>
重點(diǎn)在于getSummaries這個(gè)自定義的方法,返回一個(gè)數(shù)組即可以顯示
getSummaries(param) {
const { columns } = param
const sums = []
columns.forEach((column, index) => {
switch (index) {
case 0:
sums[index] = '是否通過'
break
case 1:
sums[index] = 'erewrwr'
break
case 2:
sums[index] = 'erewrwr'
break
case 3:
sums[index] = 'erewrwr'
break
}
})
return sums
},element-ui中的el-table底部固定指定行
1,固定一行合計(jì)的情況
https://element.eleme.cn/#/zh-CN/component/table
直接使用官方文檔上的summary-method

2,固定指定行或者多行
使用樣式去固定
例子:(計(jì)算列表數(shù)據(jù)的平均值,最大值,最小值并固定底部)
1,計(jì)算數(shù)據(jù)的值
protected calcData(data: any) {
const sums: any = {};
const max: any = {};
const min: any = {};
const columns = this.$refs["coverTable"]?.columns;
columns.forEach((column: any, index: number) => {
if (index === 0) {
sums[column.property] = "平均值";
max[column.property] = "最大值";
min[column.property] = "最小值";
return;
}
const values = data.map((item: any) => Number(item[column.property]));
if (!values.every((value: any) => isNaN(value))) {
// 總和
sums[column.property] = values.reduce((prev: any, curr: any) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
// 最大值
max[column.property] = values.reduce((prev: any, curr: any) => {
const value = Number(curr);
if (!isNaN(value) && curr > prev) {
return curr;
} else {
return prev;
}
});
// 最小值
min[column.property] = values.reduce((prev: any, curr: any) => {
const value = Number(curr);
if (!isNaN(value) && curr > prev) {
return prev;
} else {
return curr;
}
});
} else {
sums[column.property] = "N/A";
max[column.property] = "N/A";
min[column.property] = "N/A";
}
});
const average: any = {};
for (const i in sums) {
if (!isNaN(sums[i])) {
average[i] = (sums[i] / data.length).toFixed(3);
} else {
average[i] = sums[i];
}
}
if (this.tableData.length > 0) this.tableData.push(average, max, min);
}2,對(duì)要固定的三行設(shè)置class

// 行固定
tableRowClassName(params: any) {
const { row, rowIndex } = params;
row.index = rowIndex;
// 最后三行固定
if (rowIndex + 1 === this.tableData.length - 2) {
return `tr-fixed fixed-row2`;
} else if (rowIndex + 1 === this.tableData.length - 1) {
return `tr-fixed fixed-row1`;
} else if (rowIndex + 1 === this.tableData.length) {
return `tr-fixed fixed-row`;
} else {
return ``;
}
}3, 樣式控制
.el-table {
.tr-fixed{
display: table-row;
position: sticky;
bottom: 0;
width: 100%;
td {
border: 1px solid #f3f5fa;
background: #fff;
}
}
.fixed-row{
bottom: 0;
}
.fixed-row1{
bottom: 0.5rem;
}
.fixed-row2{
bottom: 1rem;
}
}4,效果

到此這篇關(guān)于element的el-table自定義最后一行的文章就介紹到這了,更多相關(guān)element的el-table自定義最后一行內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- elementui?el-table底層背景色修改簡(jiǎn)單方法
- element表格el-table實(shí)現(xiàn)虛擬滾動(dòng)解決卡頓問題
- 關(guān)于ElementUI el-table 鼠標(biāo)滾動(dòng)失靈的問題及解決辦法
- Element-UI中el-table如何合并相同單元格
- element-ui中el-table不顯示數(shù)據(jù)的問題解決
- vue element-ui實(shí)現(xiàn)el-table表格多選以及回顯方式
- elementUI中el-table表頭和內(nèi)容全部一行顯示完整的方法
- Vue element el-table-column中對(duì)日期進(jìn)行格式化方式(全局過濾器)
相關(guān)文章
通過npm或yarn自動(dòng)生成vue組件的方法示例
這篇文章主要介紹了通過npm或yarn自動(dòng)生成vue組件的方法示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2019-02-02
vue實(shí)現(xiàn)手機(jī)號(hào)碼的校驗(yàn)實(shí)例代碼(防抖函數(shù)的應(yīng)用場(chǎng)景)
這篇文章主要給大家介紹了關(guān)于vue實(shí)現(xiàn)手機(jī)號(hào)碼的校驗(yàn)的相關(guān)資料,主要是防抖函數(shù)的應(yīng)用場(chǎng)景,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
vue緩存之keep-alive的理解和應(yīng)用詳解
這篇文章主要介紹了vue緩存之keep-alive的理解和應(yīng)用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
iview實(shí)現(xiàn)select tree樹形下拉框的示例代碼
這篇文章主要介紹了iview實(shí)現(xiàn)select tree樹形下拉框的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-12-12
解決vue組件沒顯示,沒起作用,沒報(bào)錯(cuò),但該顯示的組件沒顯示問題
這篇文章主要介紹了解決vue組件沒顯示,沒起作用,沒報(bào)錯(cuò),但該顯示的組件沒顯示問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來(lái)看看吧2020-09-09
詳解vue-cli快速構(gòu)建vue應(yīng)用并實(shí)現(xiàn)webpack打包
這篇文章主要介紹了詳解vue-cli快速構(gòu)建vue應(yīng)用并實(shí)現(xiàn)webpack打包,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-12-12
vue全局方法plugins/utils的實(shí)現(xiàn)示例
很多時(shí)候我們會(huì)在全局調(diào)用一些方法,本文主要介紹了vue全局方法plugins/utils的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-07-07

