ProGridSign in

Examples

Toolbar controls

Every built-in control — quick filter, column chooser, pivot toggle, chart, refresh, expand — can be a button, a menu item, or gone, from one prop.

Live demo

Toolbar controls

Toggle controls on and off · Collapse everything into the settings menu

import { useState } from "react"
import { ProGrid, type ProColumnDef, type ToolbarConfig, type ToolbarControl } 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 layoutDemoRows = operationOrders.slice(0, 40)

const TOOLBAR_DEMO_KEYS = [
  "headerFilters",
  "refresh",
  "expand",
  "groups",
  "pivot",
  "chart",
  "columns",
] as const satisfies readonly (keyof ToolbarConfig)[]

type ToolbarDemoKey = (typeof TOOLBAR_DEMO_KEYS)[number]

const TOOLBAR_DEMO_LABELS: Record<ToolbarDemoKey, string> = {
  headerFilters: "Header filters",
  refresh: "Refresh",
  expand: "Expand",
  groups: "Groups",
  pivot: "Pivot",
  chart: "Chart",
  columns: "Columns",
}

const TOOLBAR_PLACEMENTS: { value: ToolbarControl; label: string }[] = [
  { value: true, label: "Button" },
  { value: "menu", label: "Menu" },
  { value: false, label: "Off" },
]

const DEFAULT_TOOLBAR_DEMO_CONFIG: Record<ToolbarDemoKey, ToolbarControl> = {
  headerFilters: "menu",
  refresh: true,
  expand: true,
  groups: true,
  pivot: true,
  chart: true,
  columns: true,
}

export function ToolbarControlsDocsDemo() {
  const [config, setConfig] = useState(DEFAULT_TOOLBAR_DEMO_CONFIG)
  const [settings, setSettings] = useState(true)

  return (
    <div className="space-y-3">
      <div className="flex flex-wrap items-center gap-3 border-b border-border pb-3 text-sm">
        <label className="flex cursor-pointer items-center gap-1.5 font-medium">
          <input
            type="checkbox"
            checked={settings}
            onChange={(e) => setSettings(e.target.checked)}
          />
          Settings dropdown
        </label>
        {!settings && (
          <span className="text-xs text-muted-foreground">
            Off — every control below set to &quot;Menu&quot; falls back to its own button instead
            of disappearing.
          </span>
        )}
      </div>

      <div className="grid grid-cols-1 gap-x-6 gap-y-2 sm:grid-cols-2 lg:grid-cols-3">
        {TOOLBAR_DEMO_KEYS.map((key) => (
          <div key={key} className="flex items-center gap-2 text-sm">
            <span className="w-28 shrink-0 text-muted-foreground">{TOOLBAR_DEMO_LABELS[key]}</span>
            <div className="flex overflow-hidden rounded-md border border-border">
              {TOOLBAR_PLACEMENTS.map((p) => (
                <button
                  key={String(p.value)}
                  onClick={() => setConfig((c) => ({ ...c, [key]: p.value }))}
                  aria-pressed={config[key] === p.value}
                  className={`px-2 py-1 text-xs ${
                    config[key] === p.value ? "bg-primary text-primary-foreground" : "hover:bg-muted"
                  }`}
                >
                  {p.label}
                </button>
              ))}
            </div>
          </div>
        ))}
      </div>

      <ProGrid<OperationOrder>
        columns={baseColumns}
        data={layoutDemoRows}
        getRowId={(row) => row.id}
        height={340}
        initialGrouping={["region"]}
        title="Orders"
        toolbar={{ ...config, settings }}
      />
    </div>
  )
}
Header filters
Refresh
Expand
Groups
Pivot
Chart
Columns

Orders

Row GroupsRegion
Region
Order
Customer
Status
Units
Revenue
Total
Sum8580
Sum$1,742,820
40 rows

Things to try

  • Toggle controls on and off
  • Collapse everything into the settings menu

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 Layout.

Use ProGrid in your project