This section describes two different strategies for managing reference data in your application. Both approaches implement the same grid example so they can be easily compared.
The examples contained within this section use the following reference data. Note that the data returned from the server only contains codes (keys) which must be mapped to names (values) for display purposes.
Value Handlers can be used to map keys contained within the row data to their corresponding display values. This approach involves more coding but allows for different data formats and offers more flexibility managing the data.
The main idea of this approach is to use a
valueFormatter to convert the code (key) to a value which
is displayed in the cell. Then use a
valueParser to convert the name back to a code (key) when saving
it down into the underlying data.
When using the
TextCellEditor with reference data, you may want to display the formatted text rather
than the code. In this case you should also include the
useFormatter property as follows:
Here we present the same grid example but this time using the
refData ColDef property. This approach
requires less coding and is more straightforward, however it may not be flexible enough for scenarios involving
more complex reference data formats.
All that is required with this approach is to specify the
refData and the grid will take care of the rest,
as shown below:
Like in the previous example using Value Handlers, where the underlying data contains codes, the grid will use the specified reference data to display the associated values in the cells and save down the codes (keys) in the data when editing.
The following example demonstrates how Value Handlers can be combined to work with reference data:
useFormatter=true. Mapped names are displayed in the cells and edited values are saved as 'colour' codes in the underlying data. (Note a valid name must be entered).
The following example demonstrates how the
refData property simplifies working with reference data:
refDataproperty specified. Mapped names are displayed in the drop down list and selections are saved as 'make' codes in the underlying data.
refDataproperty specified. Mapped names are displayed in the drop down list and selections are saved as 'colour' codes in the underlying data.
refDataproperty specified. Mapped names are displayed in the cells and edited values are saved as 'colour' codes in the underlying data. (Note a valid name must be entered).