gridcn1.2.2

Row operations

Insert, duplicate, and delete rows from the toolbar or the context menu, with the onDataChange operation payload visible.

Row operations from two surfaces at once: the toolbar acts on the current row selection (falling back to the active cell's row), and the right-click context menu acts on the clicked row. The side panel prints the last onDataChange payload. Every row operation emits one change with source: "row-operation" and row-id-based insert/delete operations, which is what undo/redo and export consume.

Select rows (or just click a cell) and use the toolbar, or right-click a row for the context menu. The panel shows the last onDataChange payload.

Read-only
Name
Role
Age
Silent Tiger
Viewer
63
Quick Lion
Viewer
67
Swift Wolf
Manager
40
Eager Lion
User
50
Eager Tiger
Viewer
45
Silent Wolf
User
24
Swift Lion
Viewer
34
Eager Lion
Manager
21
pnpm dlx shadcn@latest add @gridcn/data-grid-row-ops-demo

What's in the demo

  • Toolbar: Insert above / Insert below / Duplicate / Delete on the selected rows (insertRows(anchor, 1, position), duplicateRows(indices), deleteRows(indices))
  • Right-click a row for the context menu's Insert/Duplicate/Delete items (needs createRow/duplicateRow on the provider, or those items are hidden)
  • The Read-only toggle flips the provider's readOnly: every mutating surface disables
  • Side panel: the last change's source and one line per operation (type → rowId)

The operation-shape contract

onDataChange={(next, change) => {
  // change.source === "row-operation" for insert/duplicate/delete
  // change.ops: id-keyed { type: "insert" | "delete", rowId, row, index }
}}

Operations are keyed by row id, not index, so the same change stays valid across sorts and filters. That's what makes undo/redo restore the exact previous state in one step.

Behavior reference

On this page