gridcn2.0.0
Row examples

Row actions example

Add a pinned column of Edit, Duplicate, and Delete buttons to each row, built from renderCell and the grid actions.

A row actions column is a read-only column pinned to the end side (pin: "end"). Its renderCell draws buttons, and each button calls a grid action. The grid needs no extra feature for this pattern.

Each row's end-pinned column offers inline Edit / Delete buttons plus a "more" dropdown (Edit, Duplicate, Delete) — all plain store actions.

Name
Role
Age
Actions
Silent Tiger
Viewer
63
Quick Lion
Viewer
67
Swift Wolf
Manager
40
Eager Lion
User
50
Eager Tiger
Viewer
45
Silent Wolf
User
24
pnpm dlx shadcn@latest add @gridcn/data-grid-actions-demo

The two patterns

  • Inline buttons suit one or two actions that every row uses. They take horizontal space in each row.
  • A "more" dropdown suits three or more actions, or rare ones. It adds one click to each action.

The demo shows both. Two icon buttons run Edit and Delete, and a dropdown holds Edit, Duplicate, and Delete.

How it is wired

renderCell receives rowId. startEditing, duplicateRows, and deleteRows take the row id. Call useDataGridActions in a component that renderCell renders:

import {
  DataGrid,
  defineColumns,
  useDataGridActions,
} from "@/components/data-grid/data-grid";
import { Button } from "@/components/ui/button";

type Row = { id: string; name: string };

function RowActions({ rowId }: { rowId: string }) {
  const actions = useDataGridActions();

  return (
    <div className="flex justify-end gap-1">
      <Button
        size="sm"
        variant="ghost"
        onClick={() => actions.startEditing({ rowId, columnId: "name" })}
      >
        Edit
      </Button>
      <Button
        size="sm"
        variant="ghost"
        onClick={() => actions.duplicateRows([rowId])}
      >
        Duplicate
      </Button>
      <Button
        size="sm"
        variant="ghost"
        onClick={() => actions.deleteRows([rowId])}
      >
        Delete
      </Button>
    </div>
  );
}

const columns = defineColumns<Row>()([
  { id: "name", header: "Name", accessorKey: "name" },
  {
    id: "actions",
    header: <span className="sr-only">Actions</span>,
    accessorFn: () => "",
    pin: "end",
    readOnly: true,
    width: 220,
    renderCell: ({ rowId }) => <RowActions rowId={rowId} />,
  },
]);

const rows: Row[] = [{ id: "1", name: "Ada" }];

function ActionsGrid() {
  return (
    <DataGrid
      defaultData={rows}
      columns={columns}
      getRowId={(row) => row.id}
      duplicateRow={(row) => ({ ...row, id: crypto.randomUUID() })}
    />
  );
}

startEditing starts an edit in the cell that the row id and the column id name. Without a duplicateRow prop, duplicateRows does nothing and warns in development.

duplicateRowsAt and deleteRowsAt take view indexes. renderCell also receives viewRowIndex, the position of the row in the view.

On this page