Table: Reflow
The reflow table mode works by collapsing the table columns into a stacked presentation that looks like blocks of label/data pairs for each row.
Quick LinksReflow basics
The reflow responsive table only requires a table with a data-role="table"
on the table element. There is no need to set the data-mode
attribute since reflow
is the default. Be sure to include thead
and tbody
elements in your table. This example also uses the preset responsive breakpoint, applied via the ui-responsive
class.
Rank | Movie Title | Year | Rating | Reviews |
---|---|---|---|---|
Rank1 | Movie TitleCitizen Kane | Year1941 | Rotten Tomato Rating100% | Reviews74 |
Rank2 | Movie TitleCasablanca | Year1942 | Rotten Tomato Rating97% | Reviews64 |
Rank3 | Movie TitleThe Godfather | Year1972 | Rotten Tomato Rating97% | Reviews87 |
Rank4 | Movie TitleGone with the Wind | Year1939 | Rotten Tomato Rating96% | Reviews87 |
Rank5 | Movie TitleLawrence of Arabia | Year1962 | Rotten Tomato Rating94% | Reviews87 |
Rank6 | Movie TitleDr. Strangelove Or How I Learned to Stop Worrying and Love the Bomb | Year1964 | Rotten Tomato Rating92% | Reviews74 |
Rank7 | Movie TitleThe Graduate | Year1967 | Rotten Tomato Rating91% | Reviews122 |
Rank8 | Movie TitleThe Wizard of Oz | Year1939 | Rotten Tomato Rating90% | Reviews72 |
Rank9 | Movie TitleSingin' in the Rain | Year1952 | Rotten Tomato Rating89% | Reviews85 |
Rank10 | Movie TitleInception | Year2010 | Rotten Tomato Rating84% | Reviews78 |
Making the table responsive
By default, a table with reflow mode will display the stacked presentation style on all screen widths. The styles to make the table responsive are added by applying a media query with rules to switch to the tabular style presentation above a specific screen width.
This is done by wrapping a few simple CSS rules in and a media query that only applies the rules above a certain width breakpoint. The styles make the table header rows visible, display the cells in a tabular format, and hide the generated label elements within each. Here is an example media query that swaps the presentation at 40em (640 pixels):
@media ( min-width: 40em ) {
/* Show the table header rows and set all cells to display: table-cell */
.my-custom-breakpoint td,
.my-custom-breakpoint th,
.my-custom-breakpoint tbody th,
.my-custom-breakpoint tbody td,
.my-custom-breakpoint thead td,
.my-custom-breakpoint thead th {
display: table-cell;
margin: 0;
}
/* Hide the labels in each cell */
.my-custom-breakpoint td .ui-table-cell-label,
.my-custom-breakpoint th .ui-table-cell-label {
display: none;
}
}
It's best to use a class
on the table to apply the breakpoint. Add these rules to your custom stylesheet that is included in the head
of the page. We recommend creating a set of custom breakpoint classes that can be used to apply standard table breakpoints in your project.
Choosing a breakpoint
The goal is to determine the minimum width at which the entire table will fit comfortably within the screen. Find this width by populating a table with realistic sample data, then adjust the browser window until the table completely fits and has a bit of extra space to account for rendering differences across devices. This is the natural place to set the breakpoint that switches between the stacked and tabular presentation modes. The breakpoint width is highly dependent on the number of columns in the table and content within each cell.
TopApplying a preset breakpoint
Even though we strongly encourage you to write custom breakpoints yourself, the framework includes a single pre-configured breakpoint that targets the stacked style to smaller phones and swaps to a tabular presentation on larger phones, tablet and desktop devices. To use this preset breakpoint, add the ui-responsive
class to the table to convert from the stacked presentation to a tabular presentation at 560px (35em). If this breakpoint doesn't work for your content, we encourage you to write a custom breakpoint as described above.
<table data-role="table" class="ui-responsive">
TopGrouped column headers
It's fairly common to need to logically group multiple columns together under a heading group for financial or scientific data. The framework can support the most simple version of this by allowing for two rows of table headers (th
), with the first row containing simple colspan
attributes to group the columns below. In this configuration, the framework will add a class to the label of the first cell in each group to allow you to style these differently and provide additional visual hierarchy.
Paris | Average Temperatures (C) | Average Rainfall | ||
---|---|---|---|---|
MonthMonth | Minimum TempMinimum Temp | Maximum TempMaximum Temp | Precipitation (mm)Precipitation (mm) | Rainfall DaysRainfall Days |
MonthJanuary | Average Temperatures (C)Minimum Temp3 | Maximum Temp8 | Average RainfallPrecipitation (mm)17.8 | Rainfall Days10 |
MonthFebruary | Average Temperatures (C)Minimum Temp2 | Maximum Temp9 | Average RainfallPrecipitation (mm)21.7 | Rainfall Days9 |
MonthMarch | Average Temperatures (C)Minimum Temp4 | Maximum Temp13 | Average RainfallPrecipitation (mm)24.2 | Rainfall Days10 |
MonthApril | Average Temperatures (C)Minimum Temp6 | Maximum Temp15 | Average RainfallPrecipitation (mm)24.6 | Rainfall Days11 |
MonthMay | Average Temperatures (C)Minimum Temp10 | Maximum Temp20 | Average RainfallPrecipitation (mm)26.2 | Rainfall Days10 |
MonthJune | Average Temperatures (C)Minimum Temp13 | Maximum Temp23 | Average RainfallPrecipitation (mm)25.1 | Rainfall Days9 |
MonthJuly | Average Temperatures (C)Minimum Temp15 | Maximum Temp25 | Average RainfallPrecipitation (mm)21.7 | Rainfall Days7 |
MonthAugust | Average Temperatures (C)Minimum Temp15 | Maximum Temp25 | Average RainfallPrecipitation (mm)21.4 | Rainfall Days7 |
MonthSeptember | Average Temperatures (C)Minimum Temp11 | Maximum Temp21 | Average RainfallPrecipitation (mm)15.6 | Rainfall Days8 |
MonthOctober | Average Temperatures (C)Minimum Temp9 | Maximum Temp17 | Average RainfallPrecipitation (mm)25.3 | Rainfall Days11 |
MonthNovember | Average Temperatures (C)Minimum Temp5 | Maximum Temp11 | Average RainfallPrecipitation (mm)22.4 | Rainfall Days12 |
MonthDecember | Average Temperatures (C)Minimum Temp3 | Maximum Temp8 | Average RainfallPrecipitation (mm)26.6 | Rainfall Days12 |