Skip to content

edit

Ready-made checks for an editable column, and its editor.

TypeEditChecks<T, V>
Defaultnot set
Live update (update())Yes — give the columns again (update({ columns }))
Declared inpackages/core/src/columns/defs.ts

Checked in this order, after the codec has read the value:

  • required: an empty value is refused.
  • min, max: compared by the column’s codec — a number, a Day, an instant.
  • pattern: a regular expression (or its source) the whole text must match; the flags g, y and m are dropped.
  • options: the allowed values, a list or a function (row, context); the cell’s current value always passes. A list column is chosen in the list editor (editors({ list: listEditor }), from @dzgrid/dom/editors-list).

maxLength caps what the field accepts; editor names your own editor part. A bad rule is told with an invalid-column warning at columns.<id>.edit.<key>, and that rule is ignored. validate runs after these.

import { createGrid, type GridMessages } from '@dzgrid/dom';
import { edit } from '@dzgrid/dom/edit';
import { editors } from '@dzgrid/dom/editors';
import { EN_EDIT } from '@dzgrid/dom/locales/en-edit';
import { EN_EDITORS } from '@dzgrid/dom/locales/en-editors';
import { EN } from '@dzgrid/dom/locales/en';
type Gnome = { id: string; name: string; hat: string; height: number };
const messages: GridMessages = { ...EN, text: { ...EN.text, ...EN_EDIT.text, ...EN_EDITORS.text } };
createGrid<Gnome>(document.getElementById('gnomes')!, {
rows: [{ id: 'g1', name: 'Barnaby', hat: 'red', height: 31 }],
columns: [
{ id: 'name', header: 'Name', editable: true, edit: { required: true, maxLength: 40 } },
{ id: 'height', header: 'Height (cm)', type: 'number', editable: true, edit: { min: 5, max: 120 } },
],
getRowId: (r) => r.id,
messages,
features: [edit<Gnome>(), editors()],
});

Empty a Name, or give a Height over 120: the value is refused.