ProGridSign in

Examples

Selection and clipboard

Select whole rows with checkboxes, or drag a rectangular cell range like a spreadsheet and copy it out as tab-separated text that pastes cleanly into Excel or Sheets.

Live demo

Selection and clipboard

Drag across cells · Shift-click to extend the range · Right-click and copy · Tick a few row checkboxes

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

Things to try

  • Drag across cells
  • Shift-click to extend the range
  • Right-click and copy
  • Tick a few row checkboxes

The Code tab above is the component rendering this page; the Data tab is what reaches the grid. The props behind it are explained in Selection and clipboard.

Use ProGrid in your project