ProGridSign in

Examples

Column types

Declare what a column's values are and the grid picks the operators, filter editor, alignment, comparison and formatting for you.

Live demo

Column types

Filter the date column · Filter the boolean column · Sort the array column

import { ProGrid, type ProColumnDef } from "@/components/pro-grid"
import { formatCurrency, operationOrders, type OperationOrder } from "@/lib/operations-data"

/**
 * One column per primitive, so every editor and comparison is reachable.
 *
 * The boolean and array columns are derived rather than stored: the demo dataset
 * has no such fields, and `accessorFn` is how a real projection would surface
 * them anyway.
 */
const typedColumns: ProColumnDef<OperationOrder>[] = [
  { accessorKey: "id", header: "Order", size: 110, meta: { label: "Order", type: "string" } },
  {
    accessorKey: "updatedAt",
    header: "Updated",
    size: 130,
    meta: {
      label: "Updated",
      type: "date",
      formatValue: (value) => new Date(String(value)).toLocaleDateString(),
    },
  },
  {
    id: "expedited",
    accessorFn: (row) => row.priority === "Critical",
    header: "Expedited",
    size: 110,
    cell: ({ getValue }) => (getValue() ? "Yes" : "No"),
    meta: { label: "Expedited", type: "boolean" },
  },
  {
    id: "tags",
    accessorFn: (row) => [row.channel, row.priority],
    header: "Tags",
    size: 190,
    cell: ({ getValue }) => (getValue() as string[]).join(", "),
    meta: { label: "Tags", type: "array" },
  },
  {
    accessorKey: "revenue",
    header: "Revenue",
    size: 128,
    meta: {
      label: "Revenue",
      type: "number",
      align: "right",
      formatValue: (value) => formatCurrency(Number(value)),
    },
  },
]

const basicDemoRows = operationOrders.slice(0, 18)

export function ColumnTypesDocsDemo() {
  return (
    <ProGrid<OperationOrder>
      columns={typedColumns}
      data={basicDemoRows}
      getRowId={(row) => row.id}
      height={330}
      title="One column per type"
      toolbar={{ pivot: false, chart: false, refresh: false }}
    />
  )
}

One column per type

Order
Updated
Expedited
Tags
Revenue
18 rows

Things to try

  • Filter the date column
  • Filter the boolean column
  • Sort the array column

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 Column types.

Use ProGrid in your project