-
Notifications
You must be signed in to change notification settings - Fork 0
Data Formatter
##Data Formatters
The built-in $rndrFormattersTemplates.numberFormat
formatter generator can be used to create formatters. It takes in an opts
object with the following keys:
Key | Type | Default value | Description |
---|---|---|---|
digitsAfterDecimal |
number | 2 | The number of decimal points to display. |
scaler |
number | 1 | The scalar multiplier applied to the result. |
thousandsSep |
string | ',' | The string used for thousands places. |
decimalSep |
string | '.' | The string used for decimal points. |
prefix |
string | '' | The prefix string to prepend to the resuls. |
suffix |
string | '' | The suffix string to concact to the resuls. |
showZero |
boolean | false | Whether or not to display 0 or '' when the result is equal to 0. |
For example let's say I wanted a successRate
aggregator with French-style number formatting. I could use:
// for the purpose of this example let's assume that the variable `aggregatorTemplates` is the `ngRndr.aggregatorTemplates` module and the variable `dataUtils` is the `ngRndr.dataUtils` module and both are available in the current lexical scope (it could have been injected, created, or passed in).
var sumOverSum = aggregatorTemplates.sumOverSum;
var numberFormat = dataUtils.numberFormat;
var frFormat = numberFormat({thousandsSep:" ", decimalSep:","});
var successRate = function() { return sumOverSum(frFormat)(["successes", "trials"]); }
If you wanted an aggregator more like the built-in one where the user could specify which fields are "successes" and "trials", but still with French-style number formatting, then you would peel off one layer of function calls:
// for the purpose of this example let's assume that the variable `aggregatorTemplates` is the `ngRndr.aggregatorTemplates` module and the variable `dataUtils` is the `ngRndr.dataUtils` module and both are available in the current lexical scope (it could have been injected, created, or passed in).
var frFormat = dataUtils.numberFormat({thousandsSep:" ", decimalSep:","});
var frenchSumOverSum = aggregatorTemplates.sumOverSum(frFormat);
##Built-in Data Formatters
Some built-in data formatters are available in the $rndrFormatters
dictionary, and these are created by using the built-in $rndrFormattersTemplates.numberFormat
helper as described above. The following are configured with $rndrFormatters
by default:
-
usFmt()
: returns a function that takes in a number and returns a standard US formatted number. -
usFmtInt()
: returns a function that takes in a number and returns a standard US formatted integer. -
usFmtPct()
: returns a function that takes in a number and returns a standard US formatted percentage.