Shadcn React Table

Search documentation

Search the docs

Column filtering

Each column can expose its own filter control in a per-column filter row. Toggle the row with the funnel icon in the toolbar, or have it open from the start with defaultShowColumnFilters: true.

Column filters
GitHub
ID
2261
45000134754
099
AvaThompsonOwnerEngineeringactive22$45,000Jan 2, 2023
0%
LiamNguyenAdminMarketinginactive25$47,137Jan 13, 2023
9%
NoahSilvaEditorDesignpending28$49,274Jan 24, 2023
18%
EmmaCarterViewerSalesactive31$51,411Feb 4, 2023
27%
OliviaRossiOwnerSupportinactive34$53,548Feb 15, 2023
36%
WilliamWalkerAdminEngineeringpending37$55,685Feb 26, 2023
45%
SophiaPatelEditorMarketingactive40$57,822Mar 9, 2023
54%
JamesMullerViewerDesigninactive43$59,959Mar 20, 2023
63%
IsabellaParkOwnerSalespending46$62,096Mar 31, 2023
72%
LucasReyesAdminSupportactive49$64,233Apr 11, 2023
81%
$4,120,536
Rows per page
1–10 of 48

Choosing a filter control

The UI for each filter is chosen by the column's meta.variant. Supported variants are "text" (default), "select", "multi-select", "checkbox", "range", "range-slider", "date", and "date-range".

For select and multi-select, supply meta.options as an array of { label, value }. If you omit them, the options are derived from the column's faceted unique values.

import { DataTable, useDataTable } from "@/components/ui/data-table"

const columns = [
  { accessorKey: "title", header: "Title", meta: { variant: "text" } },
  {
    accessorKey: "status",
    header: "Status",
    meta: {
      variant: "select",
      options: [
        { label: "Active", value: "active" },
        { label: "Archived", value: "archived" },
      ],
    },
  },
  { accessorKey: "score", header: "Score", meta: { variant: "range" } },
]

const table = useDataTable({ data, columns, getRowId: (row) => row.id })
return <DataTable table={table} />

Open the filter row by default

const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  defaultShowColumnFilters: true,
})

Custom filter UI

Use meta.renderColumnFilter as an escape hatch to render your own filter control for a column.

Match highlighting

Matched substrings in cells are highlighted by default. Disable it for the whole table with enableFilterMatchHighlighting: false, or for a single column with meta.disableHighlight: true.

Disabling a column's filter

Set enableColumnFilter: false on a column to remove its filter control entirely.

Faceted values

Select / multi-select filters auto-derive their options, and range filters their min/max bounds, from the data's faceted values. This is on by default; set enableFacetedValues: false to skip computing the faceted row models (e.g. for very large client-side datasets) — then provide meta.options explicitly for select-style filters.

Relevant options

useDataTable options that affect column filtering:

PropTypeDefaultDescription
defaultShowColumnFilters?booleanfalseInitially show the filter row. Uncontrolled.
showColumnFilters?booleanControlled filter-row visibility. Pair with `onShowColumnFiltersChange`; omit for uncontrolled (seed with `defaultShowColumnFilters`).
onShowColumnFiltersChange?(showColumnFilters: boolean) => voidCalled whenever the filter row is shown or hidden.
enableColumnFilterModes?booleantrueShow the filter-mode menu adornment on filter fields. Default true.
enableFilterMatchHighlighting?booleantrueHighlight matched substrings in cells. Default true.
enableFacetedValues?booleantrueCompute faceted unique values / min-max (auto select options + range bounds). Default true; disable to skip the faceted row models.
columnFilterDisplayMode?ColumnFilterDisplayMode"subheader"Where column filter inputs live: `"subheader"` (a filter row under the header, default), `"popover"` (per-column popovers opened from the column header), or `"custom"` (you render them).

Per-column, via columnDef.meta:

meta keyTypeDescription
variant?FilterVariantFilter UI variant rendered in the filter row. Defaults to "text".
options?DataTableFilterOption[]Options for `select` / `multi-select` filter variants. If omitted for a select-style variant, options are derived from faceted unique values.
filterMode?FilterModeDefault filter mode for this column (overrides the per-variant default).
enableColumnFilterModes?booleanPer-column override for the filter-mode menu (defaults to the table).
renderColumnFilter?(props: { column: Column<TData, TValue> table: DataTableInstance<TData> }) => React.ReactNodeCustom filter UI for this column (escape hatch). Replaces the variant.
columnFilterModeOptions?FilterMode[]Restrict (and order) the filter-mode menu for this column to this subset of modes. Include the column's default mode.
disableHighlight?booleanOpt this column out of match highlighting.