Formatter
Method summary
name | description |
---|---|
formatEntityValue | For a given entity convert the original value to the display value. |
formatNumber | Format a number using a specified format definition. |
getFormattedLabel | For a given entity in a scenario get the formatted label for the original value. |
setEntityFormatter | Attach a formatting function for a specific entity. |
Members
-
format - {
typestring }
-
System default formats. Can be overridden globally.details
Properties:
propertiesName Type Description integer typestringDefault formatting string used for integers. decimal typestringDefault formatting string used for decimal numbers. Example
examplesinsight.Formatter.format.decimal = '#.#' // display decimals with 1 point precision.
Methods
- formatEntityValue ( entity, originalValue, key ) → {string}
-
For a given entity convert the original value to the display value.
Parameters:
paramsName Type Argument Description entity typeModelEntityThe entity instance originalValue typestringThe original value key typeArray.<*>optional The array key for the value, if applicable detailsReturns:returns tableType Description typestringThe formatted value Example
examples
Back to Topvar view = insight.getView(); var entity = view.getApp().getModelSchema().getEntity(name); insight.Formatter.formatEntityValue(entity, 1234);
- formatNumber ( original, format, locale ) → {string}
-
Format a number using a specified format definition.
Parameters:
paramsName Type Argument Description original typenumber | stringOriginal number format typestringFormat definition locale typestringoptional Locale to use for formatting detailsReturns:returns tableType Description typestringThe formatted number as a string. Empty string if original is null or undefined. Example
examples
Back to Topinsight.Formatter.formatNumber(12.75, '00#'); // returns the string '013'
- getFormattedLabel ( entity, scenario, originalValue, key ) → {string}
-
For a given entity in a scenario get the formatted label for the original value. Will discover associated label entity and use corresponding value from that.
Parameters:
paramsName Type Argument Description entity typeModelEntityThe entity instance scenario typeScenarioThe scenario to use when formatting the value originalValue typestringThe original value key typeArray.<*>optional The array key for the value, if applicable detailsReturns:returns tableType Description typestringThe formatted value Example
examples
Back to Topvar view = insight.getView(); var entity = view.getApp().getModelSchema().getEntity(name); // Scenario instance is passed in to ScenarioObserver#notify callbacks insight.Formatter.getFormattedLabel(entity, scenario, value);
- setEntityFormatter ( entity, formatter )
-
Attach a formatting function for a specific entity.
Parameters:
paramsName Type Description entity typeModelEntity | stringEither an Insight entity or an entity name formatter typefunctionThe formatter function. Callback arguments: - {*} value Original value as a primitive data type
- {Array.<*>} [key] The array key for the value, if applicable
- {*} The formatted value as a primitive type
detailsExample
examples
Back to Topfunction myFormatFunction(value, key) { // process value and return as formatted string. } insight.Formatter.setEntityFormatter(name, myFormatFunction);
© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.