Skip to content

useTableFiltering

@astryxdesign/core v0.7.1 · useTableFiltering

Usage ​

Table plugin that adds column filters with popover or inline controls. A column gets a filter when its filter names a field in fields. In the inline variant the control sits in the header cell under the column label; inline-compact puts the same control in a tighter frame when the table is short on space; in the popover variant it hides behind a funnel button and applies on confirm. Pairs with useTableFilterState for managed state.

ts
import { useTableFiltering, useTableFilterState } from '@astryx-vue/core/Table'

Five field types are supported, and each one gets a matching control:

typeControlMatches
stringtext inputa substring of the cell text
enumselectone option, exactly
multi-selectmulti-select listany one of the picked options
numbernumber inputthe same number
datedate pickera cell date later than the picked day
ts
const fields: TableFilterField[] = [
  { key: 'name', label: 'Name', type: 'string' },
  { key: 'role', label: 'Role', type: 'enum', options: roleOptions },
  { key: 'teams', label: 'Teams', type: 'multi-select', options: teamOptions },
  { key: 'age', label: 'Age', type: 'number', min: 18, max: 70, isIntegerOnly: true },
  { key: 'hired', label: 'Hired', type: 'date' },
]

applyTableFilters() returns the rows that match every active filter, so the plugin never touches data itself.

ts
const { filters, onFilterChange } = useTableFilterState()
const filterPlugin = useTableFiltering(() => ({
  filters: filters.value,
  onFilterChange,
  fields,
  variant: 'inline',
}))
const rows = computed(() => applyTableFilters(employees, filters.value, fields))

The config is read again on every access, so pass a getter when the filters live in a ref. A plain object works too, but the table keeps the filters it saw first.

In the inline variants a filtered column that declares no width gets proportional(1), so the control has room to sit under the label.

This filtering is separate from Power Search. A column without filter is never filtered, and the plugin renders nothing for it.

Examples ​

Table — Inline Filters

Name
Email
Role
Department
Alice Johnsonalice@example.comEngineerPlatform
Bob Smithbob@example.comDesignerProduct
Charlie Browncharlie@example.comManagerPlatform
Diana Princediana@example.comEngineerInfra
Eve Daviseve@example.comAdminOperations

Table with inline filter controls rendered directly below each column header.

Table — Popover Filters

Name
Email
Role
Department
Alicealice@example.comEngineerPlatform
Bobbob@example.comDesignerProduct
Charliecharlie@example.comManagerPlatform
Dianadiana@example.comEngineerInfrastructure
Eveeve@example.comAdminOperations

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