Get Free Trial
API reference
Table of contents

setFormat

setFormat(format: FormatObject, measureName: String, aggregation: String)

[starting from version: 1.4]

Sets a default number format or the number format for the specified measure.

To apply a default format to all measures, leave the measureName and aggregation parameters undefined.

To apply a format only to a specific measure, specify the measureName and aggregation parameters. Learn more in this guide: Number formatting.

Use refresh() API call after setting a format to redraw the component and see changes.

Parameters

  • formatFormatObject. It contains the number format parameters.
  • measureName optional – String. The measure’s unique name.
    To apply the format to a specific measure, specify the measureName parameter. The aggregation parameter must be specified as well unless the measure is calculated.
    To override a default format for all measures, leave the measureName and aggregation undefined. Note that in this case, the name property in the format object should be an empty string ("").
  • aggregation optional — String. The measure’s aggregation. If the measure is calculated, skip the aggregation property.

Examples

1) How to override a default number format at runtime:

let format = {
  name: "",
  decimalPlaces: 0,
  thousandsSeparator: ","
};
flexmonster.setFormat(format);
flexmonster.refresh();

Try how the sample works on JSFiddle.

2) How to change a currency symbol for a specific measure:

let format = flexmonster.getFormat("Price", "sum");
format.name = "PriceFormat";
format.currencySymbol = "$";
//format.currencySymbol = "£" // pound sterling
//format.currencySymbol = "€" // euro
//format.currencySymbol = "¥" // yen
flexmonster.setFormat(format, "Price", "sum");
flexmonster.refresh();

Open the example on JSFiddle.

See also

getFormat
FormatObject
refresh
Number formatting tutorial