ProGridSign in

Examples

Filtering

Text, number, date, set and boolean filters driven by column type. Every surface — header funnel, filter bar, side rail, dialog — edits one filter model.

Live demo

Filtering

Open a header filter · Combine two conditions · Move the filters to the rail · Clear everything from the toolbar

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

const FILTER_PLACEMENTS = ["top", "left", "dialog", "none"] as const

export function FilteringDocsDemo() {
  const [placement, setPlacement] =
    useState<NonNullable<FilterConfig["placement"]>>("top")
  const [headerFilters, setHeaderFilters] = useState(true)

  return (
    <div className="space-y-3">
      <div className="flex flex-wrap items-center gap-3 text-sm">
        <span className="text-muted-foreground">Placement</span>
        <div className="flex overflow-hidden rounded-md border border-border">
          {FILTER_PLACEMENTS.map((p) => (
            <button
              key={p}
              onClick={() => setPlacement(p)}
              aria-pressed={placement === p}
              className={`px-3 py-1 text-xs capitalize ${
                placement === p ? "bg-primary text-primary-foreground" : "hover:bg-muted"
              }`}
            >
              {p}
            </button>
          ))}
        </div>
        <label className="flex cursor-pointer items-center gap-1.5 text-xs text-muted-foreground">
          <input
            type="checkbox"
            checked={headerFilters}
            onChange={(e) => setHeaderFilters(e.target.checked)}
          />
          Header funnels
        </label>
      </div>

      <ProGrid<OperationOrder>
        columns={baseColumns}
        data={filterDemoRows}
        getRowId={(row) => row.id}
        height={340}
        title="Orders"
        filters={{ placement, headerFilters }}
      />
    </div>
  )
}
Placement

Orders

FiltersNo filters yet — add one →
Order
Customer
Region
Status
Units
Revenue
Total
Sum8580
Sum$1,742,820
40 rows

Things to try

  • Open a header filter
  • Combine two conditions
  • Move the filters to the rail
  • Clear everything from the toolbar

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

Use ProGrid in your project