ProGridSign in

Features

Selection and clipboard

Select rows for actions or build spreadsheet-like cell ranges with pointer and keyboard input. Both modes are enabled by default and can be controlled independently.

Interaction model

  • Click or drag to replace the active cell range. The cell you clicked is the anchor, drawn with a ring.
  • Hold Shift while clicking or pressing an arrow key to extend from the anchor.
  • Click a column header to select the whole column; Shift-click a second header to select the span.
  • Use row checkboxes for record-level actions that should survive sorting. Starting a cell range clears them, and vice versa.
<ProGrid
  columns={columns}
  data={orders}
  rowSelection
  cellSelection
  getRowId={(order) => order.id}
/>

Keyboard

Once a cell has been clicked, the body has keyboard focus and these keys act on the range. Group summary rows are stepped over.

KeysAction
↑ ↓ ← →Move the active cell; the range collapses to it.
Shift + arrowsExtend the range from the anchor.
Home / EndFirst / last column of the row. With Ctrl, the first / last cell of the grid.
Page Up / Page DownMove by a viewport of rows.
Ctrl + ASelect every cell.
Ctrl + CCopy the range (or the checked rows). Ctrl + Shift + C includes the header row.
EscClear the range.

Cmd stands in for Ctrl on macOS.

Live demo

Row and cell selection

Use the checkboxes for rows, or click and drag through cells to create a range.

import { useState } from "react"
import { ProGrid, type ProColumnDef } 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)

export function SelectionDocsDemo() {
  const [selectionCount, setSelectionCount] = useState(0)

  return (
    <>
      <div className="docs-demo__status" aria-live="polite">
        <span>{selectionCount ? `${selectionCount} row${selectionCount === 1 ? "" : "s"} selected` : "Select rows or drag across cells"}</span>
        <span>Arrows move · Shift extends · Ctrl/⌘+C copies</span>
      </div>
      <ProGrid<OperationOrder>
        columns={baseColumns.slice(0, 5)}
        data={selectionDemoRows}
        getRowId={(row) => row.id}
        height={360}
        onStateChange={(state) => setSelectionCount(Object.keys(state.rowSelection).length)}
        title="Pick fulfillment orders"
      />
    </>
  )
}
Select rows or drag across cellsArrows move · Shift extends · Ctrl/⌘+C copies

Pick fulfillment orders

Order
Customer
Region
Status
Units
Total
Sum5184
24 rows

Row actions

rowActions puts a ⋮ menu of record-level actions in the utility column, and the same affordance in its header for whatever is currently selected. The actions are yours: the grid renders the trigger and the menu and calls back.

  • items takes an array, or a function of the row when the menu has to vary — the usual reason being an action that does not apply to every record.
  • hidden drops an item; disabled greys it but leaves it visible, which is the better choice when its absence would be puzzling.
  • variant colours an item primary, warning or destructive. It is styling only — a destructive action that needs confirming should ask in its own onSelect, using whatever your application already uses for that.
  • position: "trailing" moves the actions into their own column pinned to the right edge, instead of sharing the checkbox column.
<ProGrid
  columns={columns}
  data={orders}
  getRowId={(order) => order.id}
  rowActions={{
    // "leading" (default) shares the checkbox column; "trailing" gets its own,
    // pinned to the right edge.
    position: "leading",
    items: (row) => [
      { id: "edit", label: "Edit", icon: <Pencil />, onSelect: ({ row }) => edit(row.original) },
      {
        id: "delete",
        label: "Delete",
        icon: <Trash2 />,
        variant: "destructive",
        hidden: row.original.status === "Complete",
        onSelect: ({ row }) => remove(row.original),
      },
    ],
    // The header menu, over the current selection.
    bulkItems: [
      { id: "export", label: "Export selected", onSelect: ({ rows }) => exportRows(rows) },
    ],
  }}
/>

Group and aggregate rows never get a trigger: they stand for a bucket rather than a record, so a verb like Delete has nothing to act on. Narrow it further with isRowActionable.

Live demo

Row actions

Open the ⋮ menu on any row, or select rows and use the menu in the header. Delete is hidden on completed orders.

import { useState } from "react"
import { Ban, Copy, Download, Pencil, Trash2 } from "lucide-react"
import type { Row } from "@tanstack/react-table"
import { ProGrid, type ProColumnDef, type RowAction } 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)),
    },
  },
]

/**
 * Record-level actions in the utility column, beside the checkbox.
 *
 * `items` is a function here so Delete can withhold itself from an order that
 * has already shipped — the common reason a menu varies per row. The header's
 * `⋮` runs the same verbs over everything currently selected.
 */
export function RowActionsDocsDemo() {
  const [log, setLog] = useState<string | null>(null)
  const [rows, setRows] = useState(() => operationOrders.slice(0, 18))

  const say = (message: string) => setLog(message)

  // `items` is handed the TanStack row, as `onRowClick` and `rowClassName` are;
  // the record itself is `row.original`.
  const items = (row: Row<OperationOrder>): RowAction<OperationOrder>[] => {
    const order = row.original
    return [
    { id: "edit", label: "Edit order", icon: <Pencil />, onSelect: () => say(`Edit ${order.id}`) },
    { id: "duplicate", label: "Duplicate", icon: <Copy />, onSelect: () => say(`Duplicated ${order.id}`) },
    {
      id: "hold",
      label: "Put on hold",
      icon: <Ban />,
      variant: "warning",
      onSelect: () => say(`${order.id} put on hold`),
    },
    {
      id: "delete",
      label: "Delete order",
      icon: <Trash2 />,
      variant: "destructive",
      // A shipped order is a record of something that happened; it is amended,
      // not deleted. `hidden` drops the item rather than greying it out.
      hidden: order.status === "Complete",
      onSelect: () => {
        setRows((prev) => prev.filter((r) => r.id !== order.id))
        say(`Deleted ${order.id}`)
      },
    },
    ]
  }

  const bulkItems: RowAction<OperationOrder>[] = [
    {
      id: "export",
      label: "Export selected",
      icon: <Download />,
      onSelect: ({ rows: picked }) => say(`Exported ${picked.length} order${picked.length === 1 ? "" : "s"}`),
    },
    {
      id: "delete-many",
      label: "Delete selected",
      icon: <Trash2 />,
      variant: "destructive",
      onSelect: ({ rows: picked }) => {
        const ids = new Set(picked.map((r) => r.original.id))
        setRows((prev) => prev.filter((r) => !ids.has(r.id)))
        say(`Deleted ${ids.size} order${ids.size === 1 ? "" : "s"}`)
      },
    },
  ]

  return (
    <>
      <div className="docs-demo__status" aria-live="polite">
        <span>{log ?? "Open the ⋮ menu on a row, or select rows and use the one in the header"}</span>
        <span>Delete is hidden on completed orders</span>
      </div>
      <ProGrid<OperationOrder>
        columns={baseColumns.slice(0, 5)}
        data={rows}
        getRowId={(row) => row.id}
        height={360}
        rowActions={{ items, bulkItems }}
        title="Fulfillment orders"
      />
    </>
  )
}
Open the ⋮ menu on a row, or select rows and use the one in the headerDelete is hidden on completed orders

Fulfillment orders

Order
Customer
Region
Status
Units
Total
Sum3465
18 rows

Clipboard

Copy serializes the range as tab-separated text, formatted the way the cells display it, so it pastes straight into a spreadsheet. Cells containing a tab, line break or quote are quoted. The context menu offers the same copy with the header row, and, while rows are grouped, laid out under their group summaries.