After editing a cell, the grid normally inserts the new value into your data using the column
attribute. If it's not possible to use a field attribute, you can provide a Value Setter instead.
A Value Setter is the inverse of a Value Getter. Where the value getter allows getting values from your data using a function rather than a field, the value setter allows you to set values into your data using a function rather than specifying a field.
The parameters provided to a value setter are as follows:
A value setter should return
true if the value was updated successfully and
if the value was not updated (including if the value was not changed). When you return
grid knows it must refresh the cell.
The following is an example of how you would configure a column using the field attribute and then follows how the same can be done using value getters and value setters.
Example: Value Setter
The example below demonstrates value setters working alongside value getters (value setters are typically only used alongside value getters). Note the following:
- All columns are editable. After an edit, the example prints the updated row data to the console to show the impact of the edit.
Column A uses
fieldfor both getting and setting the value. This is the simple case for comparison.
Column B uses
valueSetterinstead of field for getting and setting the value. This allows the value to be parsed into the correct type before being saved.
Column Name uses
valueGetterto combine the value from the two attributes
valueSetteris used to break the value up into the two same attributes.
Column C.X and C.Y use
valueGetterto get the value from an embedded object. They then use
valueSetterto set the value into the embedded object while also making sure the correct structure exists (this structure creation would not happen if using field).