Validation
FlexGrid helps with validation in several ways:
- Automatic Type Coercion: When cell edits are committed, the grid automatically coerces values to match the column's data type. It also checks for nulls and empty values based on the column's isRequired property. If the data is invalid, the original cell value is restored.
- Data Maps: If your grids contain columns that should only allow certain input values, add a DataMap to the column to ensure users will not be able to type invalid content into the cells.
- Event-Based Validation: The grid raises a cellEditEnding event that allows you to check the editor's current value and cancels the edit if the new value is invalid.
- CollectionView-Based Validation: The grid honors the collection view's getError method to highlight invalid cells and to prevent users from entering invalid information.
The grid below demonstrates the first three ways of validation. It has a Country column with a data map that prevents users from entering invalid countries. The cellEditEnding event is used to ensure that the 'Sales' and 'Expenses' columns contain positive values: