Core Features

Advanced Features

JavaScript Data GridCell Editing Validation

Version 36.2.0

Standard Validation Copy Link

The Grid provides built-in validation for all Provided Cell Editors, such as the Text, Large Text, Number and Date editors. These editors support validation automatically by checking the constraints defined in the column configuration. For example:

  • Text and Large Text editors will respect the maxLength property.
  • Number editors validate against min and max constraints.
  • Date editors ensure the value is a valid date string.

Provided editors validate as their value changes and run a final validation when editing ends. The Grid handles invalid values based on the selected Validation Modes.

Overriding Validation Copy Link

To customise validation in a Provided Editor, use the getValidationErrors() callback inside ICellEditorParams. The callback receives the editor's internalErrors, and its return value replaces the Provided Editor's validation result. Include internalErrors in the returned array if the built-in constraints should still apply alongside your custom rules.

Properties available on the ICellEditorParams<TData = any, TValue = any, TContext = any> interface.

getValidationErrorsCopy Link
Function
Optional validation callback that will override the getValidationErrors() of Provided Editors. Use this to return your own custom errors.
Returns: An array of non-empty, user-facing error messages, or null if the editor is valid.
const gridOptions = {
    columnDefs: [
        {
            field: 'athlete',
            cellEditorParams: {
                getValidationErrors: (params) => {
                    const { value, internalErrors } = params;
                    const errors = [...(internalErrors ?? [])];
                    if (!value || value.length < 3) {
                        errors.push('The value has to be at least 3 characters long.');
                    }

                    return errors.length ? errors : null;
                },
            },
        },
    ],

    // other grid options ...
}

If the callback returns errors, the Grid will show the errors in a tooltip when hovering the editor and discard the edit value before completing (depending on the Validation Modes).

This is demonstrated in the following example, note that:

  • Athlete has to be at least 3 characters.
  • Age has to be different than 18.

Validation Modes Copy Link

The Grid supports two modes for handling invalid edits, configured via the grid option invalidEditValueMode:

ModeDescription
'revert' (default)Cancels the edit and reverts the cell to its original value if the value is invalid.
'block'Keeps the invalid editing session open until a valid value is provided or the edit is cancelled. Full Row Editing still allows navigation between editors in the same row.

Use the 'block' mode when you want to strictly enforce valid input before allowing the user to proceed.

const gridOptions = {
    invalidEditValueMode: 'block',

    // other grid options ...
}

Full Row Editing Validation Copy Link

When using Full Row Editing, the Grid will validate each cell editor in the row individually, using the same mechanisms described in the previous sections.

In addition, the Grid can also perform cross-field validation by using the optional callback getFullRowEditValidationErrors(params). This allows you to implement logic that checks relationships between fields — for example, ensuring that one field is greater than another.

This callback should return an array of non-empty, user-facing error strings if the row is in an invalid state. If no errors are found, it should return null.

The row data is not updated until the edit is committed. Use editorsState to validate the proposed row values; each entry contains the column ID together with its old and new values.

getFullRowEditValidationErrorsCopy Link
GetFullRowEditValidationErrors
Validates the Full Row Edit. Return non-empty, user-facing error messages, or null when the row is valid. Only relevant when editType="fullRow".
const gridOptions = {
    getFullRowEditValidationErrors: ({ editorsState }) => {
        const values = Object.fromEntries(
            editorsState.map(({ colId, newValue }) => [colId, newValue]),
        );
        const min = Number(values.min);
        const max = Number(values.max);

        if (min > max) {
            return ['Min cannot be greater than Max'];
        }
        return null;
    },

    // other grid options ...
}

A row edit will only complete successfully if both the individual cell editors and the full-row validation return no errors.

Accessibility Copy Link

When a cell or full-row validation error is added, or its wording changes, the Grid announces the relevant error details to screen reader users. Revalidating unchanged errors, for example when navigating between editors in the same row, does not repeat the announcement.

If invalidEditValueMode is set to 'block' and prevents the user from completing a full-row edit, the Grid announces a summary of the current errors even if they were announced previously. Cell editor errors are identified by their column name. Errors returned by getFullRowEditValidationErrors apply to the row as a whole, so each error message should identify the fields or condition that the user needs to correct.

The full-row announcement text can be customised through the ariaFullRowValidationError and ariaFullRowEditValidationFailed localisation keys. In a blocked-completion summary, ariaRowIndex identifies errors that belong to another edited row and distinguishes errors from multiple rows.

This is demonstrated in the following example. Note the following validation rules:

  • Weight has to be between 0 and 500, inclusive.
  • Height has to be between 0 and 300, inclusive.
  • Full Row Edit Validation ensures that the Body Mass Index (BMI), calculated using height and weight, is between 10 and 80.

Validation of Custom Editors Copy Link

Custom Cell Editors can participate in the Grid's validation system by optionally implementing the following methods:

Properties available on the ICellEditor<TValue = any> interface.

getValidationElementCopy Link
Function
Optional: Returns the element to use for validation feedback. Called by the grid in two contexts:
  • tooltip: true → used as the anchor for validation tooltips.
  • tooltip: false → receives the invalid CSS class for visual feedback.
  • If omitted, the grid falls back to the cell element for inline editors. Popup editors that do not implement this will not show validation styles or tooltips. tooltip - Whether the element is for a tooltip or direct styling.
    Returns: An HTML element for feedback, or null/undefined to use default behavior.
    getValidationErrorsCopy Link
    Function
    Optional: The error messages associated with the Editor. Each error should be a non-empty, user-facing message.

    These methods are called automatically before the Grid attempts to complete the edit. You can also manually trigger validation by calling the validate() method available in the cellEditorParams, for example:

    cellEditorParams.validate();

    This is useful if you want to validate input during editing, such as in response to an onInput event in the Custom Phone Editor.