<el-table
ref="table1"
v-loading="loading"
:data=""
:stripe="true"
height="600"
show-summary
:summary-method="getSummaries"
:show-overflow-tooltip="true"
>
...
</el-table>
合计部分不显示的问题
updated() {
this.$nextTick(() => {
this.$refs["table1"].doLayout();
this.getSummaries();
});
},
合计部分保留两位小数不生效问题
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/450023c189e34ee4a350571d50de4dc6.png)
getSummaries(param) {
const { columns, data } = param;
const sums = [];
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = "总价";
return;
}
if (index === 1) {
sums[index] = "";
return;
}
if (index === 2) {
sums[index] = "";
return;
}
const values = data.map((item) => Number(item[column.property]));
console.log("values", values);
if (!values.every((value) => isNaN(value))) {
sums[index] = values.reduce((prev, curr) => {
const value = parseFloat(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
console.log("sums[index]", sums[index]);
sums[index] = parseFloat(sums[index]).toFixed(2);
return sums[index];
} else {
sums[index] = "";
}
});
return sums;
},