EXEPERTAI LAB

Research alpha

Time Machine
EXEPERTAI LAB
GALLERY / COLLECTION
← Browse Astryx gallery
Table·hook·@astryxdesign/core

useTableFiltering

Table plugin that adds inline column filters with popover or inline controls. Pairs with useTableFilterState for managed state. Supports text, select, multi-select, date, and number filter types via PowerSearch field definitions.

Open in Playground @astryxdesign/core/Table

Signature

Call shape
useTableFiltering()

Showcases and examples

2 documented examples

Table — Popover Filters

Table with popover filter controls triggered by icons in column headers.

Preview loads on approachPreview loads on approach
Exact source · table-filterable-table
// Copyright (c) Meta Platforms, Inc. and affiliates.

'use client';

import {
  Table,
  useTableFiltering,
  useTableFilterState,
  toSearchFilters,
  proportional,
} from '@astryxdesign/core/Table';
import type {TableColumn} from '@astryxdesign/core/Table';
import {usePowerSearchConfig} from '@astryxdesign/core/PowerSearch';
import type {PowerSearchFilter} from '@astryxdesign/core/PowerSearch';

interface Employee extends Record<string, unknown> {
  id: string;
  name: string;
  email: string;
  role: string;
  department: string;
}

const employees: Employee[] = [
  {
    id: '1',
    name: 'Alice',
    email: 'alice@example.com',
    role: 'Engineer',
    department: 'Platform',
  },
  {
    id: '2',
    name: 'Bob',
    email: 'bob@example.com',
    role: 'Designer',
    department: 'Product',
  },
  {
    id: '3',
    name: 'Charlie',
    email: 'charlie@example.com',
    role: 'Manager',
    department: 'Platform',
  },
  {
    id: '4',
    name: 'Diana',
    email: 'diana@example.com',
    role: 'Engineer',
    department: 'Infrastructure',
  },
  {
    id: '5',
    name: 'Eve',
    email: 'eve@example.com',
    role: 'Admin',
    department: 'Operations',
  },
];

const fieldDefs = [
  {key: 'name', type: 'string', label: 'Name'},
  {key: 'email', type: 'string', label: 'Email'},
  {
    key: 'role',
    type: 'enum',
    label: 'Role',
    enumValues: [
      {value: 'Engineer', label: 'Engineer'},
      {value: 'Designer', label: 'Designer'},
      {value: 'Manager', label: 'Manager'},
      {value: 'Admin', label: 'Admin'},
    ],
  },
] as const;

const columns: TableColumn<Employee>[] = [
  {key: 'name', header: 'Name', width: proportional(1), filter: 'name'},
  {key: 'email', header: 'Email', width: proportional(2), filter: 'email'},
  {key: 'role', header: 'Role', width: proportional(1), filter: 'role'},
  {key: 'department', header: 'Department', width: proportional(1)},
];

export default function TableFilterableTable() {
  const {config, applyFilters} = usePowerSearchConfig(fieldDefs);
  const {filters, onFilterChange} = useTableFilterState();

  const filterPlugin = useTableFiltering<Employee>({
    filters,
    onFilterChange,
    searchConfig: config,
  });

  const data = applyFilters(
    toSearchFilters(filters, columns, config) as PowerSearchFilter[],
    employees,
  );

  return (
    <Table
      data={data}
      columns={columns}
      idKey="id"
      plugins={{filter: filterPlugin}}
    />
  );
}

Usage

Table plugin that adds inline column filters with popover or inline controls. Pairs with useTableFilterState for managed state. Supports text, select, multi-select, date, and number filter types via PowerSearch field definitions.

Typed props

PropType and behavior
filtersTableFilterState · required
Current filter state: map from column key to filter value.
onFilterChange(columnKey: string, value: TableFilterValue | null) => void · required
Called when the user changes a filter value. null clears the filter.
variant'popover' | 'inline' | 'inline-compact' · default 'popover'
Display variant for filter controls.