jQuery Mobile: Table Filter

This entry is part 32 of 73 in the series jQuery Mobile

You are not limited to using filters on listviews.

To create a filter for a table, set data-filter=’true’ on the table element to generate a filter for table rows.

Table Filter
<!DOCTYPE html>
    <link href='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.css' rel='stylesheet'/>
    <script src='http://code.jquery.com/jquery-1.10.2.min.js'></script>
    <script src='http://code.jquery.com/mobile/1.4.1/jquery.mobile-1.4.1.min.js'></script>
<div data-role='page'>
    <div data-role='header'><h1>Filterable Table</h1></div>

            <input id='filterTable-input' data-type='search'>
    <table data-role='table' data-filter='true' data-input='#filterTable-input' class='ui-responsive'>
                    <th data-priority='1'>Rank</th>
                    <th data-priority='persist'>Movie Title</th>
                    <th data-priority='2'>Year</th>
                    <th data-priority='3'>Rating</th>
                    <th data-priority='4'>Reviews</th>
                        <td><a href='http://en.wikipedia.org/wiki/Citizen_Kane' data-rel='external'>Citizen Kane</a></td>
                        <td><a href='http://en.wikipedia.org/wiki/Casablanca_(film)' data-rel='external'>Casablanca</a></td>
                        <td><a href='http://en.wikipedia.org/wiki/The_Godfather' data-rel='external'>The Godfather</a></td>

    <div data-role='footer' data-position='fixed'>
Try The Code

The main line that we need to look at is:

<table data-role='table' data-filter='true' data-input='#filterTable-input' class='ui-responsive'>

In the table html tag, we need to define data-filter=’true’.

The input box needs to have data-type=’search’ with an id pointing to the table as well.

Series Navigation<< jQuery Mobile: Filterable List
jQuery Mobile: Filter Collapsible Set >>