在ui-grid中格式化页脚值

Dec*_*McD 12 javascript node.js express angularjs angular-ui-grid

如何格式化ui-grid中列的聚合值?

随着我的数字,我得到了一些可怕的东西

total: 6370.046074130321
Run Code Online (Sandbox Code Playgroud)

什么时候我想

total: $6370.05
Run Code Online (Sandbox Code Playgroud)

我试过两个:

footerCellTemplate: '<div class="ui-grid-cell-contents" >{{COL_FIELD | currency}}</div>',
Run Code Online (Sandbox Code Playgroud)

footerCellTemplate: '<div class="ui-grid-cell-contents" >{{grid.getCellValue(row, col) | currency}}</div>',
Run Code Online (Sandbox Code Playgroud)

但它们都不起作用.

Kat*_*hir 16

您尝试过的模板将适用于正常的单元格值,但您正在尝试使模板在聚合值上工作.

要获取模板中列的聚合值,您可以使用 {{col.getAggregationValue()}}并添加格式选项.

由于你想要两个小数,这更像是 {{col.getAggregationValue() | number:2 }}

还要记住,如果在网格上启用了列过滤器,模板将会有所不同.


KAR*_*N.A 6

如果您需要后小数点以显示两个值,则在网格选项中使用自定义模板功能

       {
            field: 'ORGINAL_FUNC_AMOUNT',
            displayName: 'CR A/C',
            aggregationType: uiGridConstants.aggregationTypes.sum,
            footerCellTemplate: '<div class="ui-grid-cell-contents" >Total: {{col.getAggregationValue() | number:2 }}</div>'
        }
Run Code Online (Sandbox Code Playgroud)