Dojo NG is being built in the open, one section at a time — follow along on Heptapod.

API REFERENCE · DATA GRID PLUGINS

@dojo-ng/data-grid-edit

Inline cell editing for <dj-data-grid>.

Try it in the playground

@dojo-ng/data-grid-edit · v0.1.1 · A plugin for <dj-data-grid>, not a custom element

npm install @dojo-ng/data-grid-edit

F2/Enter on the active row or double-click starts editing; Enter/blur commits, Escape cancels. The grid never mutates your data — apply the commit yourself.

<dj-data-grid id="g"></dj-data-grid>
<script type="module">
  import "@dojo-ng/data-grid";
  import { editPlugin } from "@dojo-ng/data-grid-edit";
  const g = document.getElementById("g");
  g.columns = [
    { id: "name", header: "Name", editable: true },
    { id: "qty", header: "Qty", editable: { control: "number" } },
    { id: "status", header: "Status", editable: { control: "select", options: [
      { value: "active", label: "Active" }, { value: "retired", label: "Retired" },
    ] } },
  ];
  let rows = [{ name: "Widget", qty: 2, status: "active" }];
  g.data = rows;
  g.plugins = [editPlugin()];
  g.addEventListener("dj-cell-commit", (e) => {
    const { row, columnId, value } = e.detail;
    rows = rows.map((r) => (r === row ? { ...r, [columnId]: value } : r));
    g.data = rows; // controlled: you own the data
  });
</script>

How it works

  • Editing is controlled: the plugin never writes to data. Listen for dj-cell-commit, update your data, and assign a new data array.
  • Put this plugin first in the plugins array, so its editor wins the cell over other plugins.

Options it adds

Installing this plugin adds these members to its host's types.

OptionTypeDescription
GridColumn.editableColumnEditableMake this column editable inline.

Events

These events bubble from the host element. The data is in event.detail.

dj-cell-commit

{
  row: Row;
  columnId: string;
  value: unknown;
  oldValue: unknown;
}

Functions

editPlugin

function editPlugin(): DataGridPlugin;

Types

ColumnEditable

type ColumnEditable = true | {
  control: "text" | "number" | "select";
  options?: {
    value: string;
    label: string;
  }[];
};