jQuery Mobile: Arranging 2 Buttons using Grid-A

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

Say we need to put 2 submit and reset buttons side by side on a page.

We can use grid-a to format the page.

2 Buttons in Grid
<!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>Grid A</h1></div>
    <br>
    <div class='ui-grid-a'>
        <div class='ui-block-a'><input type='submit' value='Submit' data-theme='a'></div>
        <div class='ui-block-b'><input type='reset' value='Reset' data-theme='b'></div>
    </div>

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

grid_a_buttons

Also, we have used 2 different themes for block a and block b.

jQuery Mobile: 3-column Grid B

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

Grid B is for 3-column block.

3-Column Grid
<!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>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Grid B</h1></div>
    <br>
    <div class='ui-grid-b'>
            <div class='ui-block-a'><div class='ui-bar ui-bar-a' style='height:60px'>Block A</div></div>
            <div class='ui-block-b'><div class='ui-bar ui-bar-a' style='height:60px'>Block B</div></div>
            <div class='ui-block-c'><div class='ui-bar ui-bar-a' style='height:60px'>Block C</div></div>
    </div><!-- /grid-a -->

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

gridB

As you can see, just by using class=’ui-grid-b’, we have turned the page into a 3-column block system.

jQuery Mobile: Grid

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

The jQuery Mobile framework provides a simple way to build CSS-based columns that can also be responsive.

We look at a simple example below.

To build a two-column (50/50%) layout, start with a container with a class of ui-grid-a, and add two child containers inside it classed with ui-block-a for the first column and ui-block-b for the second.

2-Column Grid
<!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>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Grid A</h1></div>
    <div class='ui-grid-a'>
            <div class='ui-block-a'><div class='ui-bar ui-bar-a' style='height:60px'>Block A</div></div>
            <div class='ui-block-b'><div class='ui-bar ui-bar-a' style='height:60px'>Block B</div></div>
    </div><!-- /grid-a -->

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

gridA

This is the grid-a with a 2-column block.

In the next example, we will use grid-b which is for 3-column block.

jQuery Mobile: Filter Reveal

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

The filter reveal feature makes it easy to build a simple autocomplete with local data.

When a filter has the data-filter-reveal=’true’ attribute, it will auto-hide all the list items when the search field is blank.

Filter Reveal
<!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>Upwhere</title>
</head>
<body>
<div data-role='page'>
    <div data-role='header'><h1>Filter Reveal</h1></div>
    <ul data-role='listview' data-filter='true' data-filter-reveal='true' data-filter-placeholder='Search fruits...' data-inset='true'>
        <li><a href='#'>Apple</a></li>
        <li><a href='#'>Banana</a></li>
        <li><a href='#'>Cherry</a></li>
        <li><a href='#'>Cranberry</a></li>
        <li><a href='#'>Grape</a></li>
        <li><a href='#'>Orange</a></li>
    </ul>

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

The data-filter-placeholder attribute can be added to specify the placeholder text for the filter.

In the example above, I have put the text search fruit as the attribute for data-filter-placeholder since the list contains mainly different types of fruits.

jQuery Mobile: Filter Collapsible Set

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

I have never seen an app that use this UI but if you have thought of a way to use it, here is the code.

Filter Collapsible Set
<!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 Collapsible Set</h1></div>
    <form>
            <input data-type='search' id='searchForCollapsibleSet'>
    </form>
        <div data-role='collapsibleset' data-filter='true' data-inset='true' data-input='#searchForCollapsibleSet'>
            <div data-role='collapsible' data-filtertext='Animals'>
                <h3>Animals</h3>
                <ul data-role='listview' data-inset='false'>
                    <li>Cats</li>
                    <li>Dogs</li>
                    <li>Lizards</li>
                    <li>Snakes</li>
                </ul>
            </div>
            <div data-role='collapsible' data-filtertext='Cars'>
                <h3>Cars</h3>
                <ul data-role='listview' data-inset='false'>
                    <li>Acura</li>
                    <li>Audi</li>
                    <li>BMW</li>
                    <li>Cadillac</li>
                </ul>
            </div>
            <div data-role='collapsible' data-filtertext='Planets'>
                <h3>Planets</h3>
                <ul data-role='listview' data-inset='false'>
                    <li>Earth</li>
                    <li>Jupiter</li>
                    <li>Mars</li>
                    <li>Mercury</li>
                </ul>
            </div>
        </div>

    <div data-role='footer' data-position='fixed'>
        <h1>Footer</h1>
    </div>
</div>
</body>
</html>
Try The Code

To use filterable collapsible set, we use the attribute data-role=’collapsibleset’.

The input box needs to have data-type=’search’ and its id is pointing towards the collapsible set.