jQuery Mobile: Table Filter

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>
<html>
<head>
    <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>
    <title>Codecrawl</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Filterable Table</h1></div>
    <br>

    <form>
            <input id='filterTable-input' data-type='search'>
    </form>
    <table data-role='table' data-filter='true' data-input='#filterTable-input' class='ui-responsive'>
            <thead>
            <tr>
                    <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>
                </tr>
            </thead>
                <tbody>
                <tr>
                        <th>1</th>
                        <td><a href='http://en.wikipedia.org/wiki/Citizen_Kane' data-rel='external'>Citizen Kane</a></td>
                        <td>1941</td>
                        <td>100%</td>
                        <td>74</td>
                    </tr>
                <tr>
                        <th>2</th>
                        <td><a href='http://en.wikipedia.org/wiki/Casablanca_(film)' data-rel='external'>Casablanca</a></td>
                        <td>1942</td>
                        <td>97%</td>
                        <td>64</td>
                    </tr>
                <tr>
                        <th>3</th>
                        <td><a href='http://en.wikipedia.org/wiki/The_Godfather' data-rel='external'>The Godfather</a></td>
                        <td>1972</td>
                        <td>97%</td>
                        <td>87</td>
                    </tr>
            </tbody>
            </table>

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
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 >>