jQuery Mobile Filters
Filterable Elements
All elements that have more than one child element, can be filtered.
How To Create a Search Field:
- The element you want to be filterable, must include the data-filter="true" attribute.
- Create an <input> element with a specified id and add the data-type="search" attribute. This will create a basic search field. Wrap the <input> in a form, and add the "ui-filterable" class to the <form> element - this will adjust the margin between the search field and the filterable element.
- Then, add the data-input attribute to the filterable element. Its value must match the id of the <input> element.
Below, we have created a filterable list view:
Search for elements in a list
<form class="ui-filterable">
<input id="myFilter"
data-type="search">
</form>
<ul data-role="listview"
data-filter="true" data-input="#myFilter">
<li><a href="#">Adele</a></li>
<li><a href="#">Billy</a></li>
<li><a href="#">Calvin</a></li>
</ul>
Try it yourself »Tip: Use a placeholder to specify a short hint that describes the expected value of the search field:
Custom Filter
The text inside each child element is the actual text that is used for filtering (like "Adele" or "B" for "Billy"). However, if you want to filter the search to a custom filter text instead, you can add the data-filtertext attribute to any child element:
If you use the data-filtertext attribute on an element, the original text/content of that particular element is ignored for filtering (In the example above, you are no longer able to search for the list item "Adele". You can only find Adele by typing the keywords "f, a, v or fav".) |
More Examples
Filter Collapsible Lists
How to filter a collapsible set of lists.
Filter Tables
How to filter a table.
Filter <div> elements
How to filter a <div> element containing child <p> elements.