element el-table 计算指定列
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
免费下载资源
·
官网说明:将show-summary
设置为true
就会在表格尾部展示合计行。默认情况下,对于合计行,第一列不进行数据求合操作,而是显示「合计」二字(可通过sum-text
配置),其余列会将本列所有数值进行求合操作,并显示出来。当然,你也可以定义自己的合计逻辑。使用summary-method
并传入一个方法,返回一个数组,
<el-table :data="distributionDetailList" border
:summary-method="getSummaries"
show-summary
>
<el-table-column type="index" prop="type" label="序号" width="50" align="center"></el-table-column>
<el-table-column label="业务线" prop="businessName" align="center">
</el-table-column>
<el-table-column label="占比(业务线)" prop="businessProportion" align="center">
</el-table-column>
<el-table-column label="比例(部门)%" prop="departmentProportion" align="center">
</el-table-column>
<el-table-column label="部门" prop="departmentName" align="center">
</el-table-column>
<el-table-column label="职级" prop="rankName" align="center"></el-table-column>
<el-table-column label="比例(职级)%" prop="rankProportion" align="center"></el-table-column>
<el-table-column label="绝对值(职级)%" prop="rankMagnitude" align="center"></el-table-column>
</el-table>
methods: {
//指定列求和
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 == 'businessProportion' ||column.property =='rankMagnitude' ) {
sums[index] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
console.log(sums )
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 个月前
更多推荐
已为社区贡献4条内容
所有评论(0)