【element-ui笔记】element中el-table(合计)计算指定列
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
1.需求:我只需要前面三列的合计,最后一列不需要
找了很久,看到element-ui里面的show-summary方法,以及自定义的:summary-method,觉得很合适
以下是官网说明:
实现代码如下:
<el-table
:data="tableData"
class="table"
fit
size="medium"
show-summary
:summary-method="getSummaries"
>
<el-table-column
prop="id"
label="ID"
width="180">
</el-table-column>
<el-table-column
prop="name"
label="姓名">
</el-table-column>
<el-table-column
prop="amount1"
sortable
label="rewardAmount">
</el-table-column>
<el-table-column
prop="amount2"
sortable
label="winningNum">
</el-table-column>
<el-table-column
prop="amount3"
sortable
label="cardNum">
</el-table-column>
</el-table>
//指定列求和
getSummaries(param) {
const { columns, data } = param;
const sums = [];
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合计';
return;
}
const values = data.map(item => Number(item[column.property]));
if (column.property === 'winningNum' ||column.property ==='rewardAmount' || column.property==='cardNum' ) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[index];
}
});
return sums
},
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐
已为社区贡献5条内容
所有评论(0)