本文主要是介绍关于el-table的show-summary,合计栏不显示以及保留两位小数问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<el-tableref="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;}// console.log("column", column);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;},
这篇关于关于el-table的show-summary,合计栏不显示以及保留两位小数问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!