简体   繁体   English

如何使用 summaryFunc/summaryTemplate 格式化 ngx-datatable 中的汇总值?

[英]How can I format the summary value in ngx-datatable with summaryFunc/ summaryTemplate?

I implemented ngx-datatable in my angular project and I need to display the summary row for my table.我在我的 angular 项目中实现了 ngx-datatable,我需要显示我的表格的摘要行。 Base on the document, I used [summaryFunc] and the summary value is showing correctly.根据文档,我使用了 [summaryFunc] 并且摘要值显示正确。 But now I need to format this value.但现在我需要格式化这个值。 For example: 1,000 USD instead of 1000.例如:1,000 美元而不是 1000 美元。

How can I do that with[summaryFunc] ?我怎么能用 [summaryFunc] 做到这一点?

  • [summaryFunc] = "sampleFunc | number" => not working, it say result of sampleFunc not a number (I also returned number inside sampleFunc). [summaryFunc] = "sampleFunc | number" => 不工作,它说 sampleFunc 的结果不是数字(我也在 sampleFunc 中返回了数字)。
  • I tried to use DecimalPipe inside sampleFunc => not working, because inside sampleFunc everything is undefined (this and all pipe...).我试图在 sampleFunc => 中使用 DecimalPipe => 不起作用,因为在 sampleFunc 内部一切都是未定义的(这个和所有管道......)。

  • I also tried to use [summaryTemplate]="sampleTemplate".我也尝试使用 [summaryTemplate]="sampleTemplate"。 samplateTempate is defined by ng-template. sampleTempate 由 ng-template 定义。 But I dont know how to passing the summary value into sampleTemplate?但我不知道如何将汇总值传递到 sampleTemplate 中?

 <ngx-datatable #table class="material" [headerHeight]="40" [footerHeight]="40" [columnMode]="'flex'" [rowHeight]="'auto'" [summaryRow]="hasSummaryRow" [summaryHeight]="45" (resize)="onResize($event)" (reorder)="onReorder($event)" (activate)="onActive($event)" [loadingIndicator]="!items" [limit]="pageItems" [rows]="items" [count]="totalItems" [externalPaging]="externalPaging" [offset]="offset" (page)="onPaging($event)"> <ngx-datatable-column *ngFor="let col of displayedColumns; let i=index" [name]="col.value" [flexGrow]="calculateWidth(col)" [sortable]="!col.columnType" [canAutoResize]="true" [resizeable]="!col.columnType" [summaryFunc]="sampleFunc" [summaryTemplate]="sampleTemplate"> </ngx-datatable-column> </ngx-datatable> <ng-template #sampleTemplate let-value="value"> <span>{{value|number}}</span> </ng-template>

Finally I my self found the answer for this... Inside the summaryFunc I just need to declare new pipe to format the number.最后我自己找到了答案......在 summaryFunc 中,我只需要声明新管道来格式化数字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM