<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();
});
},
合计部分保留两位小数不生效问题
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;
},