Our grid already has sorting, pagination, and filtering. Now it’s time to make it editable.
First, let’s modify the grid columns by adding each of them the editor property.
columns.js:
You may have noticed that all inputs as well as UIKernel.Editors.Select have some props passed to them via {...this.props}.
These props are passed through UIKernel.Grid. They include onChange, onFocus, onBlur, and value.
We’ll also need to validate our edited data. So let’s define some validation rules.
validation.js:
Here, we’ve called UIKernel.createValidator to create a validator.
field is the method of validator which accepts two parameters: a column name and a validation function.
In this example, we’ve used only UIKernel.Validators.regExp. There are many more UIKernel validation functions, see them all here.
Now let’s modify our model.js file as follows:
The last task is to make it possible to discard and save the edited data.
So we’ll define the saveChanges and clearChanges methods in our MainComponent.
MainComponent.js:
Inside saveChanges we’ve called the save method to save changes.
Inside clearChanges we’ve called the clearAllChanges method to remove changes.
To make it all work, we also need to add the ref attribute to our grid and two buttons for calling the methods we’ve just created.