Table Widgetversion added: 1.3
Description: Creates a responsive table
Responsive tables
One of the biggest challenges in responsive web design (RWD) is presenting tabular data. Large tables with lots of columns don't fit on smaller screens and there isn't a simple way to re-format the table content with CSS and media queries for an acceptable presentation. To address this, the framework offers two different options for presenting tables responsively. Each has benefits and tradeoffs, the right choice will depend on the data being presented.
Reflow mode - Re-formats the table columns at narrow widths so each row of data is presented as a formatted block of label/data pairs. This is ideal for tables with product or contact information with more complex or lengthy data formatting that doesn't need comparison across rows of data.
Column toggle mode - Selectively hides columns at narrower widths as a sensible default but also offers a menu to let users manually control which columns they want to see. This mode is better for financial data tables that have compact values and need to maintain comparisons across columns and rows of data. It can also be used for building things like product comparison tables.
The responsive table feature is built with a core table plugin (table.js
) that initializes when the data-role="table"
attribute is added to the markup. This plugin is very lightweight and adds ui-table
class, parses the table headers and generates information on the columns of data, and fires a tablecreate
event. Both the table modes, reflow and column toggle, are written as extensions to the table widget that hook in via the create
event to add the additional behaviors that make the tables responsive. Reflow is the default mode so if the extension is present, it will be applied automatically if the data-role="table"
attribute is on the table.
If only one mode is used on a project, the download builder tool can be used to package only the table plugin and the single extension to save code weight.
General table markup guidelines
Here is the basic table markup you should use for both table modes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
|
Both table modes start with standard HTML table markup but there are some specific guidelines you must follow for the responsive table to work correctly:
- Follow standard HTML table markup guidelines for proper semantics
- Do not use
rowspan
orcolspan
in your tables, these aren't supported except for grouped headers (see below) - Adding
thead
andtbody
elements are optional but provide improved semantics - Assign a unique
ID
to the table (required for the column toggle mode) - Add the
data-role="table"
to apply the responsive table plugin - The default table mode is
reflow
, adddata-mode="columntoggle"
change modes - The first row of the table must contain the table headers, be sure to use
TH
instead ofTD
tags - To display longer table header text in the column chooser or reflow labels, wrap the text in the
TH
with aabbr
element and set thetitle
. This string will be used in place.
Styling and theming tables
The responsive table plugin is as minimally styled as possible to give you a clean slate for your designs. The plugin focuses primarily on the difficult scripting elements: generating the labels for the reflow table and creating the button and column chooser popup. Out of the box, the table just has a few basic style rules to add a bit of padding and set the vertical alignment of cells to be top left for visual consistency.
The table will adapt to whatever content block it sits on, but there isn't an explicit theming attribute for this widget. We did this because it's simple enough to add theme classes like ui-body-a
to individual cells if a more heavily themed look is wanted.
Row strokes
To add horizontal lines between each row, add a custom style to your stylesheet that adds a border to the table headers and cells. In this example, RGBA is used to set a color (black) at an opacity of 5% so this will work on any background color:
1
2
3
4
5
6
7
|
|
This standard table stroke style can be also applied by adding table-stroke
class
to the table
element. If you prefer a custom stroke style, use the example above as a starting point. Note that adding styles that set a color for the stroke will override a theme class so do not use these together.
Options
classes.tableType: String
"ui-table"
The classes option is only configurable via JavaScript because it expects an object literal value.
initSelectorType: CSS selector string
":jqmData(role='table')"
1
2
3
|
|
Methods
Events
create( event, ui )Type: tablecreate
Note: The ui
object is empty but included for consistency with other events.
Initialize the table with the create callback specified:
1
2
3
|
|
Bind an event listener to the tablecreate event:
1
|
|
Example:
A basic example of a reponsive table.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
|