javascriptangularjsnode.jsexpressangular-ui-grid

Format footer values in ui-grid


How do I format the aggregate value for a column in ui-grid?

With my numbers I get something horrible like

total: 6370.046074130321

when I would like

total: $6370.05

I tried both:

footerCellTemplate: '<div class="ui-grid-cell-contents" >{{COL_FIELD | currency}}</div>',

and

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

but none of them work.


Solution

  • The templates you had tried will work for the normal cell values but your are trying to get the template work on a aggregate value.

    To get the aggregate value for the column inside a template you can use {{col.getAggregationValue()}} and add your format options.

    Since you want to have two decimals this would be more like {{col.getAggregationValue() | number:2 }}

    Also remember the template will be different if you have column filters enabled on the grid.