Components

Data Table Filter

A composable filter bar for data tables with text, number, date, option, and multi-option column types.

Client Only

Installation

pnpm dlx @docyrus/cli add @docyrus/ui-data-table-filter
UI Primitives(9 components)
npx shadcn@latest add button calendar checkbox command input popover separator slider tabs

Usage

import {
  DataTableFilter,
  useDataTableFilters
} from '@docyrus/ui/components/data-table-filter';

const columnsConfig = [
  {
    id: 'title',
    displayName: 'Title',
    icon: TextIcon,
    type: 'text' as const,
    accessor: (row: Task) => row.title
  },
  {
    id: 'status',
    displayName: 'Status',
    icon: CircleIcon,
    type: 'option' as const,
    accessor: (row: Task) => row.status,
    options: [
      { label: 'Todo', value: 'todo' },
      { label: 'Done', value: 'done' }
    ]
  },
  {
    id: 'effort',
    displayName: 'Effort',
    icon: HashIcon,
    type: 'number' as const,
    accessor: (row: Task) => row.effort,
    min: 0,
    max: 100
  },
  {
    id: 'createdAt',
    displayName: 'Created',
    icon: CalendarIcon,
    type: 'date' as const,
    accessor: (row: Task) => row.createdAt
  }
] as const;

function MyFilters() {
  const { columns, filters, actions, strategy } = useDataTableFilters({
    strategy: 'client',
    data: myData,
    columnsConfig
  });

  return (
    <DataTableFilter
      columns={columns}
      filters={filters}
      actions={actions}
      strategy={strategy}
      locale="en" />
  );
}

Features

  • 5 column data types — text, number, date, option, multiOption
  • Client & server strategies — Client-side filtering with automatic option counting, or server-side with external filter state
  • Rich operators — Type-specific operators (contains, is between, is any of, etc.)
  • i18n support — Built-in locales: English, French, Dutch, German, Chinese (Simplified & Traditional)
  • Faceted counts — Option counts with visual indicators
  • Keyboard friendly — Full keyboard navigation through filter controls
  • Mobile responsive — Adapts layout for mobile viewports
  • Controlled & uncontrolled — Use internal state or manage filters externally

API Reference

useDataTableFilters

The main hook that creates columns, manages filter state, and returns action handlers.

PropTypeDefaultDescription
strategy'client' | 'server'—Filter strategy
dataArray<TData>—Row data array
columnsConfigReadonlyArray<ColumnConfig<TData>>—Column configuration array
defaultFiltersFiltersState—Initial filter values (uncontrolled)
filtersFiltersState—External filter state (controlled)
onFiltersChangeDispatch<SetStateAction<FiltersState>>—Filter state setter (controlled)
optionsPartial<Record<OptionColumnIds, ColumnOption[]>>—Server-provided options for option columns
facetedPartial<Record<...>>—Server-provided faceted counts and min/max values

Returns:

FieldTypeDescription
columnsArray<Column<TData>>Enriched column objects with properties
filtersFiltersStateCurrent filter state
actionsDataTableFilterActionsFilter action handlers
strategyFilterStrategyActive strategy

DataTableFilter

The rendered filter bar component.

PropTypeDefaultDescription
columnsArray<Column<TData>>—Columns from useDataTableFilters
filtersFiltersState—Filter state from useDataTableFilters
actionsDataTableFilterActions—Actions from useDataTableFilters
strategyFilterStrategy—Strategy from useDataTableFilters
localeLocale'en'Display locale

Type Reference

ColumnConfig

Configuration for a single filterable column.

FieldTypeRequiredDescription
idstringYesUnique column identifier
accessor(row: TData) => TValYesFunction to extract value from row data
displayNamestringYesDisplay label for the filter UI
iconLucideIconYesIcon component shown next to the label
typeColumnDataTypeYesColumn data type
optionsArray<ColumnOption>For option/multiOptionAvailable options for selection
facetedOptionsMap<string, number>NoPre-computed faceted option counts
minnumberFor numberMinimum value constraint
maxnumberFor numberMaximum value constraint
transformOptionFn(value) => ColumnOptionNoTransform raw values to options
orderFn(a, b) => numberNoCustom sort order for options

ColumnDataType

type ColumnDataType = 'text' | 'number' | 'date' | 'option' | 'multiOption';
TypeNative ValueDescription
textstringSearchable text column
numbernumberNumeric column with range support
dateDateDate column with range support
optionstringSingle-value from a list of options
multiOptionArray<string>Zero or more values from a list of options

ColumnOption

Option item for option and multiOption columns.

FieldTypeRequiredDescription
labelstringYesDisplay label
valuestringYesInternal value
iconReactElement | ElementTypeNoIcon component or element

FilterStrategy

type FilterStrategy = 'client' | 'server';
  • client — Hook computes options, faceted counts, and min/max from the provided data array automatically.
  • server — You provide options and faceted counts externally. The hook only manages filter state.

FilterModel

Represents a single active filter.

FieldTypeDescription
columnIdstringColumn being filtered
typeColumnDataTypeColumn data type
operatorFilterOperators[type]Active operator
valuesFilterValues<type>Filter values

FiltersState

type FiltersState = Array<FilterModel>;

DataTableFilterActions

MethodSignatureDescription
addFilterValue(column, values) => voidAdd values to an option/multiOption filter
removeFilterValue(column, values) => voidRemove values from an option/multiOption filter
setFilterValue(column, values) => voidSet filter values (any type)
setFilterOperator(columnId, operator) => voidChange filter operator
removeFilter(columnId) => voidRemove a single filter
removeAllFilters() => voidClear all active filters

Locale

type Locale = 'en' | 'fr' | 'nl' | 'zh_CN' | 'zh_TW' | 'de';

Filter Operators

Text Operators

OperatorDescription
containsValue contains the search text
does not containValue does not contain the search text

Number Operators

OperatorDescription
isEquals the value
is notDoes not equal the value
is less thanLess than the value
is less than or equal toLess than or equal
is greater thanGreater than the value
is greater than or equal toGreater than or equal
is betweenBetween two values (inclusive)
is not betweenOutside the range

Date Operators

OperatorDescription
isExact date match
is notNot this date
is beforeBefore the date
is on or beforeOn or before the date
is afterAfter the date
is on or afterOn or after the date
is betweenBetween two dates
is not betweenOutside the date range

Option Operators

OperatorDescription
isMatches the selected option
is notDoes not match
is any ofMatches any of the selected options
is none ofMatches none of the selected options

Multi-Option Operators

OperatorDescription
includeIncludes the selected value
excludeExcludes the selected value
include any ofIncludes any of the selected values
include all ofIncludes all selected values
exclude if any ofExcludes if any of the values match
exclude if allExcludes if all values match

On this page