Skip to content

useTableFilters ​

Manages the table's search field, status-tab filter, and advanced filter panel — including active counts and reset/clear operations.

File: vue/src/js/hooks/table/useTableFilters.js


Props Factory ​

js
import { makeTableFiltersProps } from '@/hooks/table/useTableFilters'
PropTypeDefaultDescription
hideSearchFieldBooleanfalseHide the search input
navActiveString'all'Initial active status-tab slug
filterBtnOptionsObject{}Options for the filter button component
searchInitialValueString''Initial search string
filterListArray[]Status tab definitions [{ slug, name, number }]
filterListAdvancedObject{}Advanced filter panel definitions by category
hideFiltersBooleanfalseHide the status-tab filter bar
hideAdvancedFiltersBooleanfalseHide the advanced filter button
showMobileHeadersBooleanfalseShow column headers on mobile

Usage ​

js
import useTableFilters, { makeTableFiltersProps } from '@/hooks/table/useTableFilters'

const {
  search,
  searchModel,
  activeFilterSlug,
  activeFilter,
  mainFilters,
  advancedFilters,
  activeAdvancedFilters,
  activeFilterCount,
  setSearchValue,
  setFilterSlug,
  clearAdvancedFilter,
} = useTableFilters(props)

Returns ​

State ​

NameTypeDescription
searchRef<String>Committed search value (triggers loadItems)
searchModelRef<String>Bound to the search <v-text-field> (not yet committed)
activeFilterSlugRef<String>Currently selected status-tab slug
activeFilterComputedRef<Object>The full filter object for the active slug
mainFiltersRef<Array>Status tab list (can be updated by setMainFilters)
advancedFiltersRef<Object>Advanced filter state by category
activeAdvancedFiltersComputedRef<Object>Only the categories/filters that have a non-empty selection
activeFilterCountComputedRef<Number>Total number of active advanced filters
expandedPanelsRef<Array>Which advanced filter panels are expanded
advancedFilterMenuOpenRef<Boolean>Whether the advanced filter menu is open
filterBtnTitleComputedRef<Object>Text for the filter button (includes active filter count)

Methods ​

NameSignatureDescription
setSearchValue(value?) => BooleanCommit a new search value; returns true if changed
setFilterSlug(slug) => BooleanChange the active status tab; returns true if changed
setMainFilters(filters) => voidReplace the status tab list
setAdvancedFilters(filters) => voidReplace the advanced filter state
clearAdvancedFilter() => voidClear all advanced filter selections
resetAdvancedFilter() => voidReset all filters (alias for clear with different empty value semantics)
resetCategoryFilters(category) => voidReset filters for a single category
removeAdvancedFilter(category, slug) => voidRemove a single filter
getCategoryLabel(category) => StringHuman-readable label for a filter category
getActiveCategoryFilterCount(category) => NumberCount of active filters in a category
getFilterLabel(category, slug) => StringLabel for a specific filter
formatFilterValue(category, slug) => StringDisplay string for a filter's current value

Notes ​

  • search and searchModel are separate: searchModel is bound to the input and only commits to search when setSearchValue is called (e.g. on Enter or blur). This prevents a loadItems call on every keystroke.
  • Initial state restores from useTableState.lastParameters so filter/search survive page refreshes.

See Also ​