以ui-grid格式化页脚值
如何格式化ui-grid中列的聚合值?
用我的号码,我得到了一些可怕的东西
total: 6370.046074130321
当我想
total: $6370.05
我试了两个:
footerCellTemplate: '<div class="ui-grid-cell-contents" >{{COL_FIELD | currency}}</div>',
和
footerCellTemplate: '<div class="ui-grid-cell-contents" >{{grid.getCellValue(row, col) | currency}}</div>',
但他们都没有工作。
你已经尝试过的模板将适用于正常的单元格值,但你正试图让模板工作在一个合计值。
要获得模板内的列的聚合值,您可以使用{{col.getAggregationValue()}}
并添加您的格式选项。
既然你想要两位小数,这将更像{{col.getAggregationValue() | number:2 }}
{{col.getAggregationValue() | number:2 }}
还记得如果您在网格上启用了列filter,模板将会不同。
如果您需要小数点后显示两个值,则在网格选项中使用自定义模板function
{ 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>' }
您可以使用数字filter来select您需要的小数位数。
{{'$' + valueToFormat | number:2}}
否则,您可以使用自定义filter函数来自己过滤文本/值。
在你的模块中添加:
.filter('customFilterFunction', function() { return function(input) { var out = ""; out = '$' + parseFloat(input).toFixed(2); return out; }; })
在你的HTML中添加:
{{valueToFormat | customFilterFunction}}
$templateCache.put('ui-grid/uiGridFooterCell', "<div class=\"ui-grid-cell-contents\" col-index=\"renderIndex\"><div>{{ col.getAggregationText() + ( col.getAggregationValue() CUSTOM_FILTERS ) }}</div></div>" );
CUSTOM_FILTERS = footerCellFilter属性grid.colDef [0] .footerCellFilter ='number:2'