Shadcn React Table

Search documentation

Search the docs

Filter modes

Filter modes let users change how a column's filter is applied — for example matching with Contains, Starts with, Equals, Between, Greater than, or Empty. With enableColumnFilterModes: true (the default) each filter field shows a mode menu offering the modes appropriate to that column's meta.variant.

Filter modes
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

Setting the initial mode

Set a column's starting mode with meta.filterMode.

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

const columns = [
  {
    accessorKey: "title",
    header: "Title",
    meta: { variant: "text", filterMode: "startsWith" },
  },
  {
    accessorKey: "score",
    header: "Score",
    meta: { variant: "range", filterMode: "between" },
  },
]

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

Toggling the mode menu

enableColumnFilterModes is true by default. Turn it off globally to hide every mode menu, or override it per column with meta.enableColumnFilterModes.

const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  enableColumnFilterModes: false,
})
const columns = [
  // mode menu hidden for this column only
  { accessorKey: "id", header: "ID", meta: { enableColumnFilterModes: false } },
]

Restricting the available modes

Limit a column's mode menu to a specific subset (and order) with meta.columnFilterModeOptions. Only modes valid for the column's variant are kept; include the column's default mode.

const columns = [
  {
    accessorKey: "title",
    header: "Title",
    meta: {
      variant: "text",
      filterMode: "contains",
      columnFilterModeOptions: ["contains", "startsWith", "equals"],
    },
  },
]

Custom mode menu

Replace the built-in radio items with your own using renderColumnFilterModeMenuItems. You get the allowed modes, the currentMode, and an onSelect(mode) to switch.

import { DropdownMenuItem } from "@/components/ui/dropdown-menu"

const table = useDataTable({
  data,
  columns,
  getRowId: (row) => row.id,
  renderColumnFilterModeMenuItems: ({ modes, currentMode, onSelect }) =>
    modes.map((mode) => (
      <DropdownMenuItem
        key={mode}
        disabled={mode === currentMode}
        onClick={() => onSelect(mode)}
      >
        {mode}
      </DropdownMenuItem>
    )),
})

The global-search mode menu has the same hook: renderGlobalFilterModeMenuItems — see Global search.

Localizing mode labels

Mode menu labels are localizable via localization.filterModes.