Grid / Custom validator editing
In numerous scenarios there is a requirement to not only visualize data in a table structure, but also to edit and validate it before save changes.
The MVC grid helper supports CRUD data editing operations via a simple configuration of its data source. All you have to do to enable its data editing capabilities is to:
- set the grid's Editable configuration property:
.Editable(editable => editable.Mode(GridEditMode.InCell))
- declare field definitions through the Model configurator
- configure the DataSource for performing CRUD data operations defining its Read, Create, Update and Destroy methods
If you want to enable new records insertion, you can do that by enabling the relevant option in the grid toolbar. For deleting items you need to include a delete command column.
In this demo you can see how defining a custom validation rule via the CustomValidationProductViewModel model and the productnamevalidation function you can force a check for first capital letter for the Product Name column, when you edit the value in it.
For more details about the editing capabilities of the MVC Grid see the help article here.