angular - 带固定页脚和分页器的角度材料数据表
问题描述
我使用带有固定页脚和页眉以及分页器的 Angular Material Table。问题是我如何在页脚中显示行数据的总和。如何计算行数据以显示在页脚中。
`
<ng-container matColumnDef="quantity">
<mat-header-cell *matHeaderCellDef fxHide fxShow.gt-sm mat-sort-header>Quantity</mat-header-cell>
<mat-cell *matCellDef="let purchase" fxHide fxShow.gt-sm>
<p class="font-weight-600 text-truncate">
{{purchase.quantity}}
</p>
</mat-cell>
<mat-footer-cell *matFooterCellDef>
</mat-footer-cell>
</ng-container>
<ng-container matColumnDef="price">
<mat-header-cell *matHeaderCellDef fxHide fxShow.gt-sm mat-sort-header>Price</mat-header-cell>
<mat-cell *matCellDef="let purchase" fxHide fxShow.gt-sm>
<p class="font-weight-600 text-truncate">
{{purchase.price}}
</p>
</mat-cell>
<mat-footer-cell *matFooterCellDef> </mat-footer-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns; sticky:true"></mat-header-row>
<mat-row *matRowDef="let purchase; columns: displayedColumns;" class="contact" (click)="editPurchase(purchase)"
[ngClass]="{'accent-50':checkboxes[purchase._id]}" matRipple [@animate]="{value:'*',params:{y:'100%'}}">
</mat-row>
<mat-footer-row mat-footer-row *matFooterRowDef="displayedColumns; sticky: true"></mat-footer-row>
<mat-toolbar>
<mat-toolbar-row>
<mat-icon (click)="exportCsv(dataSource)" title="Export as CSV">save_alt</mat-icon>
<mat-paginator #paginator [length]="dataSource.filteredData.length" [pageIndex]="0" [pageSize]="10"
[pageSizeOptions]="[5, 10, 25, 100]" showFirstLastButtons>
</mat-paginator>
</mat-toolbar-row>
`
解决方案
你可以减少你的价格数组:
this.total = pricesArray.reduce((priceA, priceB) => {return priceA + priceB})
这将汇总您的所有价格,并为您提供总价
推荐阅读
- append - Power Query - 减去不连续的行并创建一个新行
- reactjs - 如何在 Nextjs 中导入两个组件
- docker - Gitlab CI。来自守护进程的错误响应:没有这样的图像
- protocol-buffers - 添加新消息后的 Proto2 编码/解码问题
- c - 为什么我在将 for 循环的乘积声明为 C 中的变量时收到此错误“错误:预期表达式”
- python - 当您知道嵌套键时访问嵌套字典?
- c++ - /d2vzeroupper MSVC 编译器优化标志在做什么?
- flutter - 我怎样才能制作这个 rtl - 颤动
- python - Numpy 获取具有当前值的邻居索引的最快方法(洪水填充)
- c# - 如何避免使用 EF Core 进行保存时的实体跟踪?