el-table合计行更新问题

说明:在使用el-table自带的底部合计功能时,初始界面不会显示合计内容

解决方案:使用 doLayout()方法

bash 复制代码
updated() {
		this.$nextTick(() => {
			this.$refs['inventorySumTable'].doLayout();
		});
	},

完整代码:

bash 复制代码
 // show-summary:展示合计行
 // summary-method:自定义合计方法
 // ref="inventorySumTable":绑定表格
            <el-table
				border
				height="100%"
				:data="tableList"
				v-loading="tableLoading"
				show-summary
				:summary-method="getSummaries"
				ref="inventorySumTable"
				:cell-style="changeCellStyle"
			>
				<el-table-column
					label="序号"
					prop="index"
					type="index"
					width="55"
					align="center"
					header-align="center"
				></el-table-column>
				<el-table-column
					label="使用单位(科室)"
					prop="useDept"
					align="center"
					header-align="center"
					show-overflow-tooltip
				></el-table-column>
				<el-table-column
					label="资产分类"
					prop="typeName"
					align="center"
					header-align="center"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column
					label="折旧合计"
					prop="sumDepreciation"
					align="center"
					header-align="center"
					show-overflow-tooltip
				></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 (
					!values.every(value => {
						return isNaN(value);
					})
				) {
					console.log(sums, column.property, 226);
					if (column.property == 'sumDepreciation') {
						sums[index] = values.reduce((prev, curr) => {
							const value = Number(curr);
							if (!isNaN(value)) {
								return prev + curr;
							} else {
								return prev;
							}
						}, 0);
					}
					if (column.property == 'sumDepreciation') {
						return (sums[index] = this.formatePrice(sums[index]));
					}
				} else {
					sums[index] = '';
				}
			});

			return sums;
		},

效果展示:

相关推荐
Patrick_Wilson7 分钟前
构建通过了,为什么有些浏览器还会白屏?
前端·javascript·浏览器
AI前端工程狮3 小时前
我把 MCP 长任务拆成三个工具,token 账单涨了 7 倍
javascript·人工智能·程序员
mONESY3 小时前
DeepAgents 从零上手:别再手搓 Harness,用中间件拼出一个调研团队
javascript
吴长建先生重名了3 小时前
一次线上MySQL慢查询Bug的复现与调优全过程
javascript
利威尔xu4 小时前
Go channel 关闭 3 个 panic:向已关闭 channel 发送,服务当场崩溃
开发语言·后端·golang·并发编程·channel
山楂树の4 小时前
Java BigDecimal笔记
java·开发语言
LVZ5 小时前
AI Agent 缺的不是更强的模型,而是一个运行时
前端·javascript·后端
1-1=05 小时前
Vue 中 Class 与 Style 绑定
前端·javascript·vue.js
闲来没事抠鼻屎5 小时前
Web打印批量出单:vue-print-designer 千页实测
vue.js
用户83134859306985 小时前
Vue3的v-if /v-show/v-else /v-else-if:区别、渲染原理、坑点与性能选型
前端·javascript·vue.js