Tables are part of the HTML specification, so they are supported in mobile devices. However, working with the space, makes for some interest viewing.
Most of the time, you first have very tall cells as the browser tries to fit all of the columns. Then you end up having to scroll your table left and right, which can make reading very difficult.
Dynamically Hiding Columns
jQuery Mobile provides a different way of solving this problem. First is you can let the user choose which columns get displayed. The second will hide columns based upon how small the display is.
To choose which columns get hidden first, you, as the designer, get to specify the importance of each column. As the size gets smaller, the less important columns, disappear from the display. This continues, till the important columns disappear, until only the critical columns remain.
To do this, you need to set two data- attributes, the data-role, and the data-mode.
<table id="table-column-toggle" data-role="table" data-mode="columntoggle"> .... </table>
Then, in the th cells for the column headers, you specify an optional data-priority value. This value will accept a number between 1 (highest priority) and 6 (lowest priority) to let jQuery Mobile know which columns it should try to keep.
To use the column toggle, you have to specify the columns you want to always appear, versus those that the user can control. To do so, you will use the data-priority setting.
If a data-priority value is not set, then that column is considered required, and will always display. Example:
<tr> <th>I'm critical. Can't be removed</th> <th data-priority="1">I'm very important</th> <th data-priority="3">I'm somewhat important</th> <th data-priority="6">I'm not important. Remove me early.</th> </tr>
If the user wants the ability to see a column, they can, via the columns button choose which will appear. Clicking on the button creates a pop up which shows which columns are visible for a user, and which ones they can see later. They simply need to click on the column header names they wish to display.
This columns button will appear to the right, and above the table.
Another way jQuery Mobile provides you to display your information, is through a process called reflow. In the data-mode attribute, if you specify reflow as the option, then it will adjust your table.
So instead of moving your data into smaller spaces, or hiding some of your columns it will instead move the data, so each cell gets its own row. This makes it easier to see/read you data.
It picks which columns to show and hide based upon the data-priority attribute. So while column toggle just looks for the attribute’s existence, reflow uses it to control the layout of the table itself.
The rest of your table definitions stay very similar, and can be seen in the example below.
<table data-role="table" id="movie-table" data-mode="reflow" class="ui-responsive"> .... </table>
Other Styling Options
jQuery Mobile will help you zebra stripe a table. All you need to do is add a class called: table-stripe to the table itself. By doing so, it will automatically apply the zebra stripe method to your table.
You can make your table appear to stand out from the page, by applying the “ui-shadow” class to the table.