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;
		},

效果展示:

相关推荐
帅那个帅7 小时前
PHP里面的抽象类和接口类
开发语言·php
咖啡の猫13 小时前
Python字典推导式
开发语言·python
leiming613 小时前
C++ vector容器
开发语言·c++·算法
SystickInt13 小时前
C语言 strcpy和memcpy 异同/区别
c语言·开发语言
CS Beginner13 小时前
【C语言】windows下编译mingw版本的glew库
c语言·开发语言·windows
FJW02081414 小时前
Python_work4
开发语言·python
多看书少吃饭14 小时前
从Vue到Nuxt.js
前端·javascript·vue.js
大学生资源网14 小时前
java毕业设计之儿童福利院管理系统的设计与实现(源码+)
java·开发语言·spring boot·mysql·毕业设计·源码·课程设计
JasmineWr14 小时前
JVM栈空间的使用和优化
java·开发语言
前端一小卒14 小时前
从 v5 到 v6:这次 Ant Design 升级真的香
前端·javascript