Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

jQuery Mobile Tables

jQuery Mobile Tables


Responsive table

Responsive design is generally used to adapt to various mobile devices of users.

We only need to use a simple class name, and jQuery Mobile will automatically adjust page content based on screen size.

Responsive tables allow page content to adapt well on both mobile and desktop devices.

There are two types of responsive tables: reflow The difference between column toggle。


reflow table

The reflow model table displays horizontally when the screen size is large enough, and when the screen size becomes small enough, all data becomes vertically displayed.

To create a table, add the

Example

data-role="table" and "ui-responsive" classes to the element:

Try it »

| Note | For responsive tables, you must include the



column toggle

The column toggle model hides data when the width is insufficient.

A column toggle table is created as follows:



By default, jQuery Mobile first hides the rightmost columns of the table. However, you can specify the order of hidden columns in the table header (

data-role="table" class="ui-responsive" andelement. Do not use the rowspan or colspan attributes; these two attributes are not supported in responsive tables. | | --- | --- |
) by adding the data-priority attribute to specify the order of hidden columns; the value of data-priority can be from 1 (highest priority) to 6 (lowest priority):



I will never be hidden 我是非常重要的列 - 我不会被隐藏 我是重要的列 - 我可能被隐藏 我是不怎么重要的列 - 我最先被隐藏
Note If you do not specify a priority for a column, the column will always exist and will not be hidden.

Combine the two code snippets above to create a column toggle table, so users can customize which columns of the table to hide:

Example

 

   

     

data-priority="6"

CustomerID

     

     

data-priority="1"

ContactName

     

data-priority="2"

Address

     

data-priority="3"

City

     

data-priority="4"

PostalCode

     

data-priority="5"

Country

   

 

 

   

     

     

     

     

     

     

     

   

 

data-role="table" data-mode="columntoggle" class="ui-responsive" id="myTable"
CustomerName
1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany

Try it »

We can use the data-column-btn-text attribute to change the text of the toggle table:

Example

id="myTable">

Try it »


Table styling

We use the "ui-shadow" class to add a shadow to the table:

Add shadow

data-column-btn-text="Click me to show or hide columns!"