ProGridSign in

Features

Cell editing

Let readers change values in place. A column opts in, the grid opens the right editor for its type, and every commit reaches you as a change to apply — the grid never writes into your rows itself.

Opting a column in

Set meta.editable. The editor follows the column's type: a text box, a number box that only accepts digits, a native date picker, true/false for a boolean, and a list as soon as the column has filterOptions (or editorOptions). Per-row exceptions — a locked record — go through isCellEditable on the grid, and editing={false} makes the whole grid read-only whatever its columns say.

const columns: ProColumnDef<Order>[] = [
  { accessorKey: "id", header: "Order" },                                    // read-only
  { accessorKey: "customer", header: "Customer", meta: { type: "string", editable: true } },
  {
    accessorKey: "status",
    header: "Status",
    meta: { type: "string", editable: true, filterOptions: ["On track", "At risk", "Delayed"] }, // a list
  },
  { accessorKey: "units", header: "Units", meta: { type: "number", editable: true } },          // a number box
  { accessorKey: "due", header: "Due", meta: { type: "date", editable: true } },                // a date picker
]
Live demo

Editing in place

Customer, Status and Units are editable. Units below 1 are declined, so the old value stays.

import { useRef, useState } from "react"
import { ProGrid, type CellEditChange, type ProColumnDef, type ProGridHandle } from "@/components/pro-grid"
import { formatCurrency, operationOrders, type OperationOrder } from "@/lib/operations-data"

function StatusCell({ value }: { value: unknown }) {
  const status = String(value)
  return <span className={`order-status order-status--${status.toLowerCase().replaceAll(" ", "-")}`}>{status}</span>
}

const baseColumns: ProColumnDef<OperationOrder>[] = [
  { accessorKey: "id", header: "Order", size: 118, meta: { label: "Order", type: "string" } },
  { accessorKey: "customer", header: "Customer", size: 190, meta: { label: "Customer", type: "string" } },
  {
    accessorKey: "region",
    header: "Region",
    size: 145,
    meta: {
      label: "Region",
      type: "string", filterVariant: "set",
      filterOptions: ["North America", "Europe", "Asia Pacific", "Latin America"],
      groupable: true,
      pivotable: true,
    },
  },
  {
    accessorKey: "status",
    header: "Status",
    size: 120,
    cell: ({ getValue }) => <StatusCell value={getValue()} />,
    meta: {
      label: "Status",
      type: "string", filterVariant: "set",
      filterOptions: ["On track", "At risk", "Delayed", "Complete"],
      groupable: true,
      pivotable: true,
    },
  },
  {
    accessorKey: "units",
    header: "Units",
    size: 88,
    meta: { label: "Units", type: "number", align: "right", aggregable: true, defaultAgg: "sum" },
  },
  {
    accessorKey: "revenue",
    header: "Revenue",
    size: 128,
    meta: {
      label: "Revenue",
      type: "number",
      align: "right",
      aggregable: true,
      defaultAgg: "sum",
      formatValue: (value) => formatCurrency(Number(value)),
    },
  },
]

const selectionDemoRows = operationOrders.slice(0, 24)

const editableColumns: ProColumnDef<OperationOrder>[] = baseColumns.map((c) => {
  const key = (c as { accessorKey?: string }).accessorKey
  // Three editors: free text, a list of the status choices, and a number. The
  // order id stays read-only — it is the row's identity.
  const editable = key === "customer" || key === "status" || key === "units"
  return editable ? { ...c, meta: { ...c.meta, editable: true } } : c
})

/**
 * Editing with plain React state: `onCellEdit` writes the change into the rows
 * the grid renders, and declines a unit count below one — which is all the
 * grid needs to know to leave the old value in place.
 *
 * Changed cells stay tinted until Save asks for them and clears the marks; a
 * declined edit leaves neither a new value nor a mark.
 */
export function EditingDocsDemo() {
  const gridRef = useRef<ProGridHandle<OperationOrder>>(null)
  const [rows, setRows] = useState(() => selectionDemoRows)
  const [last, setLast] = useState<string>("Double-click a Customer, Status or Units cell — or select one and start typing.")

  const onCellEdit = (change: CellEditChange<OperationOrder>) => {
    if (change.columnId === "units" && (typeof change.newValue !== "number" || change.newValue < 1)) {
      setLast(`Declined: units must be a number of at least 1 (got ${JSON.stringify(change.newValue)}).`)
      return false
    }
    setRows((prev) => prev.map((row) => (row.id === change.rowId ? { ...row, [change.columnId]: change.newValue } : row)))
    setLast(`${change.rowId} · ${change.columnId}: ${JSON.stringify(change.oldValue)} → ${JSON.stringify(change.newValue)}`)
  }

  return (
    <>
      <div className="docs-demo__status" aria-live="polite">
        <span>{last}</span>
        <button
          type="button"
          className="underline"
          onClick={() => {
            // What a Save button does: ask which cells are pending, then drop
            // the marks once the save has gone through.
            const pending = gridRef.current?.getEditedCells() ?? []
            setLast(
              pending.length
                ? `Saved ${pending.length} change${pending.length === 1 ? "" : "s"} — ${[...new Set(pending.map((c) => c.columnId))].join(", ")}.`
                : "Nothing to save yet.",
            )
            gridRef.current?.clearEditedCells()
          }}
        >
          Save edits
        </button>
      </div>
      <ProGrid<OperationOrder>
        ref={gridRef}
        columns={editableColumns}
        data={rows}
        getRowId={(row) => row.id}
        height={360}
        onCellEdit={onCellEdit}
        rowSelection={false}
        title="Fulfillment orders"
      />
    </>
  )
}
Double-click a Customer, Status or Units cell — or select one and start typing.

Fulfillment orders

Order
Customer
Region
Status
Units
Revenue
Total
Sum5184
Sum$1,126,044
24 rows

Interaction

GestureEffect
Double-click, Enter, F2Open the active cell's editor on its current value.
Any printable keyOpen it with that key as the new text.
Enter in the editorCommit and move down (editing.enterMoves: "none" to stay).
Tab / Shift+TabCommit and move right / left.
EscCancel, keeping the old value.
Click elsewhereCommit.
Delete / BackspaceClear every editable cell in the range.
Ctrl+VPaste a block from a spreadsheet over the range, starting at the active cell. A single value fills the whole range.
Every accepted change tints its cell — see Seeing what you changed.

Pass editing={{ startOn: "click" }} for a grid that is mostly a form, where a single click should open the editor.

Committing a change

Every commit calls onCellEdit with the row as it was, the column, and the old and new values — the new value already parsed for the column type, so a number column hands you a number. Apply it to your data however you keep it. Return false, or reject, to decline.

const [rows, setRows] = useState(initialRows)

<ProGrid
  columns={columns}
  data={rows}
  getRowId={(o) => o.id}
  onCellEdit={(change) => {
    // change: { row, rowId, columnId, oldValue, newValue }
    if (change.columnId === "units" && change.newValue < 1) return false // declined
    setRows((prev) => prev.map((r) => (r.id === change.rowId ? { ...r, [change.columnId]: change.newValue } : r)))
  }}
/>

A paste or a range clear calls onBatchEdit with every change at once when you provide it, and falls back to onCellEdit per cell otherwise.

<ProGrid
  columns={columns}
  data={rows}
  getRowId={(o) => o.id}
  liveUpdates
  onCellEdit={async (change) => {
    // The cell already shows the new value. A rejection puts the old one back.
    await api.patch(`/orders/${change.rowId}`, { [change.columnId]: change.newValue })
  }}
/>

Seeing what you changed

A cell this session changed is tinted, so a reader can look over their own work before saving it. The mark is keyed by row id rather than by position, so it stays with the record when sorting, filtering or paging moves it — and it lifts by itself when a cell is edited back to the value it started with, because that is no longer a change.

Marks last until you clear them. getEditedCells() is the pending set a Save button needs, and clearEditedCells() drops the marks once the save has landed. A declined edit leaves no mark, the same way it leaves no new value.

// On by default. Turn the tint off and keep everything else:
<ProGrid columns={columns} data={rows} editing={{ highlightEdits: false }} />

// A Save button, using the marks as the pending set.
const pending = grid.current?.getEditedCells()   // [{ rowId, columnId }, ...]
await api.save(pending)
grid.current?.clearEditedCells()                 // drop the marks once it lands

Custom editors

Pass a component as meta.editor. It receives the value, the row, and three ways out: onCommit, onCancel, and onCommitAndMove for keys that should carry on to the next cell.

import type { CellEditorProps } from "@/components/pro-grid"

function PriorityEditor({ value, onCommit, onCancel, onCommitAndMove }: CellEditorProps<Order>) {
  return (
    <select
      autoFocus
      defaultValue={String(value)}
      onChange={(e) => onCommit(Number(e.target.value))}
      onKeyDown={(e) => {
        if (e.key === "Escape") onCancel()
        if (e.key === "Tab") { e.preventDefault(); onCommitAndMove(Number(e.currentTarget.value), "right") }
      }}
    >
      {[1, 2, 3].map((p) => <option key={p} value={p}>P{p}</option>)}
    </select>
  )
}

{ accessorKey: "priority", header: "Priority", meta: { type: "number", editable: true, editor: PriorityEditor } }