jQuery Mobile - Controlgroup Filter


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.


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

<!DOCTYPE html>
      <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>

         <input data-type = "search" id = "filterControlgroup-input">
      <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>


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.

Kickstart Your Career

Get certified by completing the course

Get Started