Skip to main content
You are viewing Pre-Alpha documentation.
Vuetify0 Logo
Mode
Accessibility
Vuetify

useFilter

A composable for filtering arrays of items based on search queries, supporting both primitive values and complex objects with customizable filtering logic.

Usage

The useFilter composable provides reactive array filtering with multiple modes for different search behaviors. It works with both primitive values and complex objects, and supports filtering by specific keys.

ts
import { ref } from 'vue'
import { useFilter } from '@vuetify/v0'

const items = ref([
  { name: 'John Doe', age: 30, city: 'New York' },
  { name: 'Jane Doe', age: 25, city: 'Los Angeles' },
  { name: 'Peter Jones', age: 40, city: 'Chicago' },
])

const query = ref('doe')
const { items: filtered } = useFilter(query, items, { keys: ['name'] })

console.log(filtered.value)
// [
//   { name: 'John Doe', age: 30, city: 'New York' },
//   { name: 'Jane Doe', age: 25, city: 'Los Angeles' }
// ]

Examples

Real-time filtering with highlighted matching terms.

12 of 12 results
New York/USA
8.3M
Los Angeles/USA
3.9M
London/UK
8.8M
Paris/France
2.2M
Tokyo/Japan
13.9M
Sydney/Australia
5.3M
Toronto/Canada
2.9M
Berlin/Germany
3.6M
Singapore/Singapore
5.5M
Dubai/UAE
3.5M
San Francisco/USA
870K
Amsterdam/Netherlands
870K

Architecture

useFilter provides pure filtering logic with context support:

Filter Flow

Use controls to zoom and pan. Click outside or press Escape to close.

Filter Flow

API Reference

The following API details are for the useFilter composable.

Functions

createFilter

(options?: FilterOptions) => E

Creates a filter context with pre-configured options.

createFilterContext

(_options?: FilterContextOptions) => ContextTrinity<E>

Creates a filter context with dependency injection support.

useFilter

(query: FilterQuery, items: MaybeRef<Z[]>, options?: FilterOptions) => FilterResult<Z>

A reusable function for filtering an array of items.

useFilterContext

(namespace?: string) => E

Returns the current filter context from dependency injection.

Options

customFilter

FilterFunction

keys

string[]

mode

FilterMode

Properties

mode

FilterMode

The filter mode

keys

string[]

Keys to filter on for object items

customFilter

FilterFunction

Custom filter function

query

ShallowRef<Primitive | Primitive[]>

Current query ref

Methods

apply

<T extends Z>(query: FilterQuery, items: MaybeRef<T[]>) => FilterResult<T>

Apply filter to an array of items

Benchmarks

View benchmark source↗

OperationThroughputLatencyMargin
Create filter with default options32.0M ops/s31ns± 0.2%
Filter 1,000 string primitives with single query21.2M ops/s47ns± 7.9%
Filter 10,000 objects with some mode21.1M ops/s47ns± 0.7%
Filter 1,000 objects with single key constraint20.9M ops/s48ns± 1.2%
Native Array.filter 1,000 objects9.9k ops/s100.6μs± 0.7%
Reactive filter: access computed 100 times (1,000 items)672 ops/s1.49ms± 1.0%
Was this page helpful?

© 2016-1970 Vuetify, LLC
Ctrl+/