【问题标题】:angular Material Data Table with Fixed footer with Paginator带固定页脚和分页器的角度材料数据表
【发布时间】:2019-07-19 19:16:02
【问题描述】:

我使用带有固定页脚和页眉以及分页器的 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>

`

【问题讨论】:

  • 请说明您面临的问题以及您想要实现的目标
  • 我遇到了如何在页脚中显示行数据总和的问题。在 标签中
  • 请也发布您的组件代码

标签: angular angular-material


【解决方案1】:

你可以减少你的价格数组:

this.total = pricesArray.reduce((priceA, priceB) => {return priceA + priceB})

这将汇总您的所有价格并为您提供总价

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-05-03
  • 1970-01-01
  • 2019-06-20
  • 2020-04-26
  • 2020-04-12
  • 1970-01-01
  • 1970-01-01
  • 2020-11-25
相关资源
最近更新 更多