Tables
Tables are used to list all information from a data set. The base style establishes preferred padding, font-size, and font-weight treatments. To enhance or customize the look of the table, apply any additional classes listed below.
The default table style is a bordered cell layout with a stylized header row.
Name | Reputation | Joined | Last seen |
---|---|---|---|
Aaron Shekey | 263 7 |
Dec 1 ’17 at 20:24 | just now |
Joshua Hynes | 611 11 |
Feb 12 at 18:47 | Aug 10 at 14:57 |
Paweł Ludwiczak | 25 8 |
Nov 28 ’17 at 20:21 | 1 hour ago |
Piper Lawson | 25 3 |
Jul 5 at 14:32 | Aug 14 at 12:41 |
By default, tables are outlined, have borders on all cells, and have a styled header. Depending on the size and complexity of a table, these can all be configured.
Shows only horizontal table cell borders. Good for tables with lots of data that can be sorted and filtered.
First name | Last name | Username | |
---|---|---|---|
1 | Aaron | S. | @aarons |
2 | Joshua | H. | @joshuah |
3 | Paweł | L. | @pawełl |
4 | Ted | G. | @so-ted |
Removes most of the default borders and backgrounds. Good for tables without much data that don't need to be sorted or filtered.
First name | Last name | Username | |
---|---|---|---|
1 | Aaron | S. | @aarons |
2 | Joshua | H. | @joshuah |
3 | Paweł | L. | @pawełl |
4 | Ted | G. | @so-ted |
Removes all table cell borders.
First name | Last name | Username | |
---|---|---|---|
1 | Aaron | S. | @aarons |
2 | Joshua | H. | @joshuah |
3 | Paweł | L. | @pawełl |
4 | Ted | G. | @so-ted |
When tables have a lot of information, you can help users group information and isolate data by adding zebra striping.
First Name | Last Name | Username | |
---|---|---|---|
1 | Aaron | S. | @aarons |
2 | Joshua | H. | @joshuah |
3 | Paweł | L. | @pawełl |
4 | Ted | G. | @so-ted |
A table’s padding can be changed to be more or less condensed.
First Name | Last Name | Username | |
---|---|---|---|
1 | Aaron | S. | @aarons |
2 | Joshua | H. | @joshuah |
First Name | Last Name | Username | |
---|---|---|---|
1 | Paweł | L. | @pawełl |
2 | Ted | G. | @so-ted |
First Name | Last Name | Username | |
---|---|---|---|
1 | Aaron | S. | @aarons |
2 | Joshua | H. | @joshuah |
Table columns will size themselves based on their content. To set a specific width, you can use one of the following table cell classes to specify the width for any column.
Class | Width |
---|---|
.s-table--cell1 |
8.3333333% |
.s-table--cell2 |
16.6666667% |
.s-table--cell3 |
25% |
.s-table--cell4 |
33.3333333% |
.s-table--cell5 |
41.6666667% |
.s-table--cell6 |
50% |
.s-table--cell7 |
58.3333333% |
.s-table--cell8 |
66.6666667% |
.s-table--cell9 |
75% |
.s-table--cell10 |
83.3333333% |
.s-table--cell11 |
91.6666667% |
.s-table--cell12 |
100% |
.s-table--cell2 | No Class |
.s-table--cell3 | .s-table--cell6 | No Class | No Class | No Class |
.s-table--cell4 | No Class | No Class | No Class | No Class | .s-table--cell2 |
The default vertical alignment is middle
. You change a table’s or a specific cell’s vertical alignment by using the Vertical Alignment atomic classes.
.va-top | .va-middle | .va-bottom |
.s-table.va-bottom | .s-table.va-bottom | .s-table.va-bottom |
Text alignment can be changed at a table or cell level by using atomic text alignment classes. Columns containing copy should be left-aligned. Columns containing numbers should be right-aligned.
.ta-left | .ta-center | .ta-right |
.s-table.ta-right | .s-table.ta-right | .s-table.ta-right |
To indicate that the user can sort a table by different columns, add the s-table__sortable
class to the table.
The <th>
cells should include arrows to indicate sortability or the currently applied sorting. In addition, the column that
is currently sorted should be indicated with the is-sorted
class on its <th>
.
Listing | Status | Owner | Views | Applies |
---|---|---|---|---|
Site Reliability Engineer, Generalist |
Running | Sansa Stark | 502 | 13 |
Senior Product Designer |
Running | Robert Baratheon | 900 | 15 |
Product Manager, Developer Products |
Running | Sansa Stark | 3 | 1 |
Stacks provides built-in functionality for letting the user sort a table by the values in a column through clicking the column header. This requires the complete data to already exist in the table (e.g. it is not going to work if the table is paged and requires a call to the server to update data on sorting). See the JavaScript introduction for general information about JS in Stacks.
To make your table user-sortable, do the following:
- Style the table as sortable as explained in the section above.
- Set
data-controller="s-table"
on the<table>
element. - Set
data-target="s-table.column"
anddata-action="click->s-table#sort"
on each of the<th>
elements that control sorting. -
Add the three icons for showing ascending sort, descending sort, and unsorted to each of these header cells, hiding the first two with a
d-none
class. Add thejs-sorting-indicator
class to each of the icons, and addjs-sorting-indicator-asc
,js-sorting-indicator-desc
, andjs-sorting-indicator-none
to the appropriate icon.Note: Usingjs-…
classes is not really the optimal way of doing this, and will probably replaced with something better eventually. When that happens, thejs-…
mechanism will be deprecated but continue to be supported for a while, so you have ample time to update things.
By default, the data is sorted by the content of the cell. If you need to use a different value, for example because your cell contains a human-readable date, add a data-s-table-sort-val
attribute to the cell.
If a column contains any data that is not an integer, the data will be sorted lexicographically. Otherwise it will be sorted numerically, with empty cells being considered the lowest number.
If the table contains rows that should not be sorted, but rather always be at the top or always be at the bottom, add data-s-table-sort-to="top"
or data-s-table-sort-to="bottom"
to the <tr>
element.
Attribute | Applied to | Description |
---|---|---|
data-controller="s-table" |
table |
Wires up the table to the JS controller |
data-target="s-table.column" |
th |
Marks this is a sortable column for the purpose of modifying arrow icons |
data-action="click->s-table#sort" |
th |
Causes a click on the header cell to sort by this column |
data-s-table-sort-to="top" |
tr |
Forces the sorting of a row to the top |
data-s-table-sort-to="bottom" |
tr |
Forces the sorting of a row to the bottom |
data-s-table-sort-val="[x]" |
td |
Optionally use a custom value for sorting instead of the cell’s text content |
Season | Starts in month | Typical temperature in °C |
---|---|---|
Winter | December | 2 |
Spring | March | 13 |
Summer | June | 25 |
Fall | September | 13 |
Average temperature | 13 |
To help users, you can add data visualizations into table cells. These are useful to help visualize the reported data and calling extra attention to the table cell. These graphs should always be paired with a number.
Listing | Status | Owner | Source | Views | Applies | ||
---|---|---|---|---|---|---|---|
Site Reliability Engineer, Generalist |
Running | Sansa Stark | stackoverflow.com | 1,854 |
|
43 |
|
Senior Product Designer |
Running | Robert Baratheon | linkedin.com | 900 |
|
15 |
|
Product Manager, Developer Products |
Running | Sansa Stark | m.facebook.com | 3 |
|
1 |
|
Generally for a checkbox input that’s placed first in the table row for bulk actions.
Display Name | Full Name | ||
---|---|---|---|
SansaStark | Sansa Stark | sstark@company.com | |
RobertBaratheon | Robert Baratheon | rbaratheon@company.com | |
Test Developer To Be Is Not A Developer Yet | Test Developer To Be Is Not A Developer Yet | testdevelopertobeisnotadevyet@team-mgmt.dev.company.com |
Used mainly with data tables, the totals row increases the font-size for all cells within a row.
Listing | Views | Apps | App CTR |
---|---|---|---|
Site Reliability Engineer, Generalist | 6,871 | 187 | 5.02% |
Senior Product Designer | 2,242 | 196 | 16.46% |
Product Manager, Developer Products | 3,469 | 229 | 14.9% |
Totals | 12,582 | 612 | 14.65% |
For tables that include inactive or disabled rows, such as inactive users or teams, .is-disabled
can be applied to any <tr>
. Additionally, .is-enabled
can be applied to any <th>
or <td>
that you’d like to ignoring the parent disabled styling (such as a persistent link to reactivate a disabled account).
Name | Last seen | ||
---|---|---|---|
Aaron Shekey | emailaddress@website.com | just now | Remove |
Joshua Hynes | emailaddress@website.com | Sep 28 ’18 | Add |
Paweł Ludwiczak | emailaddress@website.com | Apr 17 ’19 | Add |
Piper Lawson | emailaddress@website.com | Yesterday | Remove |
Ted Goas | emailaddress@website.com | 5min ago | Remove |