Validation
Overview
rs-grid supports per-column validators. A validator is called before a cell edit is committed. If it returns an error, the edit is cancelled and a callback is fired — the data layer is never touched.
Adding a validator
Set ColumnDef::validator with a CellValidator:
The closure receives the raw cell string and must return:
Ok(())— accept the valueErr(String)— reject with an error message
Listening to validation errors
Pass on_validation_error as a prop to <GridCanvas>:
The callback fires synchronously after the edit is cancelled. Arguments:
Behaviour
- Validation runs only on user edits (
CommitEdit). Programmatic writes viaGridModel::set_cellbypass the validator. - On rejection,
CancelEditis applied automatically — the cell reverts to its previous value. No undo entry is created. Selecteditors are also validated; the selected option value is passed to the validator before commit.- Validators are synchronous. For async validation (e.g. server checks),
commit optimistically and revert via
GridCommand::Undoif the check fails.
See also
- Editing — editing lifecycle and editor types
- ColumnDef API —
CellValidatortype reference - Undo / Redo — undo stack behaviour