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
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
Filter: Color
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.
Price:
Current: 80$
Current: 120$
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
Usage
Via data attributes
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
Name | Type | Default | Description |
---|---|---|---|
data-mdb-items
|
String | - |
Sets a selector for filtering items. |
data-mdb-property
|
String | - |
Defines a filter value for an item. Swap property with a filter name that
your items should have.
|
data-mdb-filter
|
String | - |
Sets a filter handler to the input group that it is applied to. |
data-mdb-auto-filter
|
String | false |
Applied to an instance enables auto filtering by inputs. |
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. |
Import
MDB UI KIT also works with module bundlers. Use the following code to import this component: