Filters
Bootstrap 5 Filters plugin
Filters are the best way to select data that meets your requirements - they affect your search results by filtrating and sorting the dataset you pass to our component.
Note: Read the API tab to find all available options and advanced customization
Note: Currently, the plugin is only compatible with the basic MDB package imported in UMD format. More about import MDB formats.
Basic example - DOM Elements
Use the data-mdb-items
attribute to define a container with data to filter. This
is required for proper component initialization.
Add data-mdb-filter="property"
to every item you want to be filtrable. If you
want to handle your filters by inputs, make a container for them, and add
data-mdb-filter="property"
to it.
Note: You must have at least one filtrable element for a component to work properly.
Checkbox example
Note: If there is more than one option, the result of filtering will show items that match both of them.
Color example
Size example
Animations with DOM Elements
Add .animation
and .animation-name
classes to filtrable elements to
animate them. The full list of available animations you can find
here.
Data structure - array
Note: Your data-mdb-items
set can be an array of items. We made
this solution for backend needs. Just set your dataset using a constructor.
Spinner & Asynchronous Data example
Price:














Animations - Array of Items
Add .animation
and .animation-name
classes to rendered elements to
animate them. The full list of available animations you can find
here.
Filter and sort
Customization - custom filter
Pass an arrow function as the value of the filter key at the filter object to define your custom filter.
Custom sort
Pass an arrow function (with two parameters - previous and second comparing items) as the third parameter at the sort function to define your custom sort rule.
Full screen example
Filters - API
Import
Usage
Via data attributes
Using the Filters plugin doesn't require any additional JavaScript code - simply add
data-mdb-filters-init
attribute to
container with data to filter
and use other data attributes to set all options.
Via JavaScript
Via jQuery
Note: By default, MDB does not include jQuery and you have to add it to the project on your own.
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to
data-mdb-
, as in data-mdb-items=""
.
Name | Type | Default | Description |
---|---|---|---|
items
|
String | Array | null |
Sets a selector for filtering items. |
autoFilter
|
Boolean | false |
Applied to an instance enables auto filtering by inputs. |
property
|
String | Array |
|
Defines a filter value for an item. Swap property with a filter name that
your items should have. For multiple properties use array: data-mdb-property = "['red', 'green', 'blue']" .
|
filter
|
String |
|
Sets a filter handler to the input group that it is applied to. |
Methods
Name | Description | Example |
---|---|---|
dispose
|
Destroys an Filters instance |
filtersInstance.dispose()
|
filter |
Filters an instance dataset |
filtersInstance.filter(options)
|
getFilters
|
Returns all available filters |
filtersInstance.getFilters()
|
getActiveFilters
|
Returns all active filters |
filtersInstance.getActiveFilters()
|
getInstance
|
Static method which allows you to get the filters instance associated to a DOM element. |
Filters.getInstance(filtersElement)
|
clear |
Clears all filters |
filtersInstance.clear()
|
sort |
Sorts an instance dataset |
filtersInstance.sort(category, order, additionalCustomSort)
|
Events
Name | Description |
---|---|
update.mdb.filters
|
This event fires immediately when the instance filters or sort its dataset. |