GRID FEATURE
Data validation
Use declarative rules to check required values, numeric ranges, string formats, and custom conditions. The default mode may only mark invalid values, so explicitly set invalidEditMode to block saving when required.
How it works and when to use it
Empty values may pass rules other than required. For mandatory quantities, combine required with numeric rules.
In the code, grid is the Grid element prepared in the installation chapter. Check each example's data and settings, and implement the app functions and server endpoints for your project.
Example 1. Required nonnegative integer quantity
Restrict empty values, decimals, and negative numbers separately.
grid.validationRules = [
{ field: 'quantity', type: 'required', message: 'Enter a quantity.' },
{ field: 'quantity', type: 'integer', message: 'Enter a whole number.' },
{ field: 'quantity', type: 'min', value: 0, message: 'Must be at least 0.' }
];
grid.invalidEditMode = 'block';Verify the result: Block commits of invalid input. A browser number editor's min restriction and business validation may be different stages.
Example 2. Summarize errors before saving
Show the full table's error list in your app's review area.
const errors = await grid.getValidationErrors();
console.log(errors);
if (errors.length) console.warn('Some cells still need correction.');Verify the result: Read row IDs, columns, values, and error messages. Visible red indicators alone do not describe validation across the full data set.
Example 3. Track failed input
Explain validation rejections and verify that the server also rejects the same values.
grid.addEventListener('cellValidationFailed', event => console.log(event.detail));Verify the result: Identify which input in which cell caused the problem. Avoid exposing sensitive values when recording user input to reproduce errors.
Combining features and troubleshooting
Clearly choose an allow, block, or revert policy. allow applies the value while showing an error, so invalid values can remain in the data.
Distinguish invalid source data from errors in new user input. The server save API must enforce business rules too.
Related reading
- How rows, columns, and IDs relate
- Connect results and events
- Explore in Features
The guide describes which interactions are available to try.