edit
Ready-made checks for an editable column, and its editor.
| Type | EditChecks<T, V> |
|---|---|
| Default | not set |
Live update (update()) | Yes — give the columns again (update({ columns })) |
| Declared in | packages/core/src/columns/defs.ts |
What it does
Section titled “What it does”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, aDay, an instant.pattern: a regular expression (or its source) the whole text must match; the flagsg,yandmare 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.
Example
Section titled “Example”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()],});Live demo
Section titled “Live demo”Empty a Name, or give a Height over 120: the value is refused.