SAPUI5 provides two different options to convert model data to an external format for visual representation: data types and formatter functions.
While data types provide the possibility to format, parse and validate data, formatter functions allow one-way conversion only.
A formatter function has a single parameter, which is the value which needs to be formatted to an external representation.
A formatter function can be used not only to format a value, but also to do type conversion or calculate results from a given value.
Formatter functions can be defined in a separate module or locally in a view controller.
The coding example in the figure Defining a Formatter Function shows the definition of a formatter function called
classText. It is created in a separate module that is implemented in the
formatter.js file. The
classText formatter translates keys used in the model data into texts that are understandable to the user. For example, for the key value "Y", the text "Economy Class" is returned.