LyteNyte Grid logo for light mode. Links back to the documentation home page.
Cell Editing

Cell Edit Validation

Validation is essential to maintain data integrity when cell editing is enabled in LyteNyte Grid. Verify cell values and display clear error messages for invalid data.

Note

This guide builds on the concepts covered in the Cell Editing and Cell Edit Renderers documentation. We recommend reviewing those topics before proceeding.

Edit Validation

Set the editRowValidatorFn property on the grid to validate cell edit updates. LyteNyte Grid calls editRowValidatorFn at the row level, even for single-cell edits. The function must return one of these values:

  • true: Validation passed; the edit can safely be applied to the row data.
  • false: Validation failed without details. Return false only if your UI displays validation feedback in another way.
  • Record<string, unknown>: A validation error map, keyed by an error code you define, with an error message or error object as the value.

In the demo below, an editRowValidatorFn function validates that the value in the Price column is greater than 0. Double-click any cell in the Price column to begin editing. When the value is less than or equal to 0, LyteNyte Grid displays an error tooltip.

Edit Validation

Fork code on stack blitzFork code on code sandbox

The demo code validates the Price column using the code shown below. You can use editRowValidatorFn to validate any type of data and integrate any validation library.

<Grid
rowHeight={50}
columns={columns}
rowSource={ds}
slotShadows={ViewportShadows}
editMode="cell"
editRowValidatorFn={useCallback<Required<Grid.Props<GridSpec>>["editRowValidatorFn"]>((p) => {
if (typeof p.editData !== "object") return false;
const data = p.editData as Record<string, number>;
if (data.price <= 0) {
return { price: "Price must be greater than 0." };
}
return true;
}, [])}
/>

Tip

Zod is a TypeScript-first schema validation library. Consider using Zod to validate cell edits and get strong type safety.

Next Steps