Cell Editing
Grid supports Excel-like cell editing where users click on a cell to edit its value.
<Grid
controller={PageController}
records={m.records}
style="height: 400px"
scrollable
cellEditable
lockColumnWidths
onCellEdited={(change, record) => {
console.log("Cell edited:", change, record)
}}
columns={[
{
header: "Name",
field: "fullName",
editor: <TextField value={m.$record.fullName} required visited />,
},
{
header: "Continent",
field: "continent",
editor: (
<LookupField
value={m.$record.continent}
options={continentOptions}
required
autoOpen
submitOnEnterKey
/>
),
},
{
header: "Browser",
field: "browser",
editor: (
<LookupField
value={m.$record.browser}
options={browserOptions}
required
autoOpen
submitOnEnterKey
/>
),
},
{
header: "Visits",
field: "visits",
align: "right",
editor: (
<NumberField
value={m.$record.visits}
required
visited
inputStyle="text-align: right"
/>
),
},
]}
recordAlias={m.$record}
/> | Name | Continent | Browser | Visits |
|---|---|---|---|
| Alice Johnson | North America | Chrome | 45 |
| Bob Smith | Europe | Firefox | 32 |
| Carol White | Asia | Safari | 28 |
| David Brown | Europe | Edge | 51 |
| Eva Green | North America | Chrome | 19 |
| Frank Wilson | Asia | Firefox | 37 |
| Grace Lee | Europe | Chrome | 42 |
| Henry Taylor | North America | Safari | 25 |
Click on any cell to edit it. Press Enter to confirm or Escape to cancel.
Enabling Cell Editing
Set the cellEditable flag on the Grid and specify editor configurations for editable columns:
<Grid
cellEditable
lockColumnWidths
onCellEdited={(change, record) => {
console.log("Cell edited:", change, record);
}}
columns={[
{
header: "Name",
field: "fullName",
editor: <TextField value={m.$record.fullName} required />,
},
{
header: "Browser",
field: "browser",
editor: <LookupField value={m.$record.browser} options={browserOptions} autoOpen />,
},
]}
/>
Editor Configuration
The editor property accepts any widget configuration. Common editors include:
TextFieldfor text inputNumberFieldfor numeric valuesLookupFieldfor dropdown selection (useautoOpenandsubmitOnEnterKeyfor better UX)Selectfor simple option lists
onCellEdited Callback
The onCellEdited callback is triggered when a cell value changes:
onCellEdited={(change, record) => {
// change contains: { field, oldValue, newValue }
// record contains the updated record data
saveToDatabase(record);
}}
Configuration
| Property | Type | Description |
|---|---|---|
cellEditable | boolean | Enable cell editing mode. |
lockColumnWidths | boolean | Prevent column widths from changing when editing starts. |
onCellEdited | function | Callback when a cell value changes. |
editor | Widget | Column property specifying the editor widget. |
editable | boolean | Column property to disable editing for specific columns. |
See also: Row Editing, Inline Edit