data-filter="true"
, children of any element can be filtered. Every child's text is used for filtering by default, however, an option is there to set the data-filtertext
attribute on any child element string value that is taken for filtering to associate custom filter text instead. data-filter="true"
on listview is used to create a filter for the list items.This is achieved by adding ui-filterable
class to the form in which search input is wrapped and add data-input ="#id"
attribute to listview ul
and data-type="search"
attribute to <input>
element.
Eg-1:
[html]
<input id="filter1" data-type="search" placeholder="Search">
<ul data-role="listview" data-filter="true" data-input="#filter1">
<li><a href="https://www.google.com">Google Chrome</a></li>
<li><a href="#">Firefox</a></li>
<li><a href="#">Safari</a></li>
</ul>
[/html]
Eg-2:
[html]
<input id="filter2" data-type="search" placeholder="Search">
<ul data-role="listview" data-filter="true" data-input="#filter2">
<li data-filtertext="browser"><a href="#">Google Chrome</a></li>
<li><a href="#">Firefox</a></li>
<li><a href="#">Safari</a></li>
</ul>
[/html]
jQuery Mobile Filter is not limited to listview, it can also be used on select, collapsible set, table, control group, or anything inside <div>
; with <p>
element. data-filter-reveal="true"
attribute holding filter, auto-hides all the list items when nothing is entered in the search field. The attribute placeholder specifies the placeholder text for the jQuery Mobile Filter.
Eg:
[html]
<input id="filter4" data-type="search" placeholder="Search Country">
<ul data-role="listview" data-filter="true" data-filter-reveal="true" data-inset="true" data-input="#filter4">
<li><a href="#">India</a></li>
<li><a href="#">United Kingdom</a></li>
<li><a href="#">Germany</a></li>
<li><a href="#">United States</a></li>
<li><a href="#">South Africa</a></li>
<li><a href="#">Austrelia</a></li>
</ul>
[/html]
data-filter-reveal="true"
attribute holding filter, auto-hides all the list items when nothing is entered in the search field.