问题:使用element表格的合计功能,且自定义方法计算时,没有出现下方的合计。
解决方法:数据渲染之后使用一下官方的doLayout方法,一定要加上this.$nextTick
this.$nextTick(() => { this.$refs.tableRef.doLayout() })
显示:
el-table(
:data="tableData" border height="calc(100vh - 327px)" default-expand-all row-key="id"
show-summary :summary-method="getImageSummaries"
ref="tableRef"
:tree-props="{children: 'children', hasChildren: 'hasChildren'}"
v-loading="tableLoading" :header-cell-style="headerStyle"
)
el-table-column(label="序号" type="index" align="center" width="80")
el-table-column(prop="project_name" label="工程名称" align="left" show-overflow-tooltip min-width="300")
el-table-column(prop="unit" label="单位" align="center" show-overflow-tooltip min-width="100")
// 合计方法
getImageSummaries(param) {
console.log(11111,this.summaryData)
const { columns, data } = param;
const sums = [];
columns.forEach((column, index) => {
if (index === 0) {
sums[index] = '合计';
return;
}
let nums = [1,3,4,15,17]
if (nums.includes(index)) {
sums[index] = '';
return;
}
if(index === 2){
sums[index] = '万元'
}
if(index === 5){ // 本月计划
sums[index] = this.summaryData.this_month_plan
}
if(index === 6){ // 本月完成
sums[index] = this.summaryData.this_month_completed
}
});
return sums;
}