CxJS

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}
/>
NameContinentBrowserVisits
Alice JohnsonNorth AmericaChrome45
Bob SmithEuropeFirefox32
Carol WhiteAsiaSafari28
David BrownEuropeEdge51
Eva GreenNorth AmericaChrome19
Frank WilsonAsiaFirefox37
Grace LeeEuropeChrome42
Henry TaylorNorth AmericaSafari25

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:

  • TextField for text input
  • NumberField for numeric values
  • LookupField for dropdown selection (use autoOpen and submitOnEnterKey for better UX)
  • Select for 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

PropertyTypeDescription
cellEditablebooleanEnable cell editing mode.
lockColumnWidthsbooleanPrevent column widths from changing when editing starts.
onCellEditedfunctionCallback when a cell value changes.
editorWidgetColumn property specifying the editor widget.
editablebooleanColumn property to disable editing for specific columns.

See also: Row Editing, Inline Edit