我在6号角项目中有一个网格, 表格中的页脚包含2种数据类型:自定义总和和自定义平均 当我说自定义时,我的意思是我们对如何使用网格数据进行计算有自己的逻辑。 this is how the footer looks like
当我导出到excel时,页脚导出为1行,我想将其分成2行。
导出本身工作正常,我只需要将页脚分成两行
页脚代码:
<ng-template kendoGridFooterTemplate let-dataItem let-column let-columnIndex="columnIndex" >
<div>
<span *ngIf="columnIndex === 2">{{'average' | translate}}</span>
<div *ngIf="item.avg">
<span [ngClass]="getAvg(item.field) > 0 ? 'green' : 'red' ">{{getAvg(item.field) | number: '2.'}}</span>
</div>
</div>
<div>
<span *ngIf="columnIndex === 2">{{'sum' | translate}}</span>
<div *ngIf="item.sum">
<span [ngClass]="getSum(item.field) > 0 ? 'green' : 'red' ">{{getSum(item.field) | number: '2.'}}</span>
</div>
</div>
</ng-template>
我已经尝试检查是否可以添加多于1个页脚,并且找不到任何相关文档
解决方案有人:)?
答案 0 :(得分:0)
我找到了解决方案, 在onExcelExport(e:any)中,我可以访问excel工作表中的单元格并进行编辑 所以我删除了最后一行 并手动插入我需要的数据 所以代码看起来像这样:
网格设置:
<kendo-grid *ngIf="gridData"
[data]="gridData"
[pageSize]="state.take"
[skip]="state.skip"
[sort]="state.sort"
[filter]="state.filter"
filterable="menu"
(filterChange)="filterChange($event)"
[navigable]="true"
(dataStateChange)="dataStateChange($event)"
[sortable]="{
allowUnsort: true,
mode:'multiple'} "
[selectable]="true"
(excelExport)="onExcelExport($event)">
函数如下所示
onExcelExport(e: any) {
// delete last row in the excel sheet
const rows = e.workbook.sheets[0].rows;
rows.pop();
// push new row by initiate new cell array, looping throw state to get the the right field
const cellsSum = [];
const rowsLength = rows[rows.length - 1].cells.length;
for (let i = 0; i < rowsLength; i++) {
const field =
this.employeeColumnService.state.employeeDetailsColumns.find(x => x.title === rows[0].cells[i].value.toString()).field;
cellsSum.push({value: this.getSum(field)});
}
}
rows.push({type: "data", cells: cellsSum});