jQuery Mobile - Controlgroup Filter



Description

The controlgroup buttons can also be filtered using data-filter attribute on elements, which creates the controlgroup. You can also filter the elements based on the text string declared in data-filtertext attribute.

Example

Following example demonstrates the use of filterable controlgroup in jQuery Mobile.

<!DOCTYPE html>
<html>
   <head>
      <title>Filterable controlgroup</title>
      <meta name = "viewport" content = "width = device-width, initial-scale = 1">
      <link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
      <script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
      <script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
   </head>

   <body>
      <form>
         <input data-type = "search" id = "filterControlgroup-input">
      </form>
      
      <div data-role = "controlgroup" data-filter = "true" 
         data-input = "#filterControlgroup-input">
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all">Button 1</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all" 
            data-filtertext = "two">Button 2</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all" 
            data-filtertext = "three">Button 3</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all">Button 4</a>
         <a href = "#" class = "ui-btn ui-shadow ui-corner-all">Button 5</a>
      </div>
      
   </body>
</html>

Output

Let's carry out the following steps to see how the above code works −

  • Save the above html code as filterable_controlgroup.html file in your server root folder.

  • Open this HTML file as http://localhost/filterable_controlgroup.html and the following output will be displayed.

jquery_mobile_widgets.htm
Advertisements