Tables
Tables should be consistently styled across the site. Use of the CSS class listing accomplishes this goal.
Including the tableListing stylesheet
<link rel='stylesheet' type='text/css' href='/styles/css/tableListing.css' />
Removing a row from a table (javascript)
var listTable = document.getElementById('somethingTable');
var listRow = document.getElementById('prefix_' + myIdentifier);
var r = listRow.rowIndex;
listTable.deleteRow(r);
Standard table with <thead>, <tbody> and <tfoot> sections.
Alignment comes from classes tdl, tdc, and tdr.
Vertical alignment comes from classes top, middle, and bottom.
Default vertical alignment is middle (determined by browser).
| Standard Table with 3 Columns & colspans | |||
|---|---|---|---|
| Column | tdl | tdc | tdr |
| Table Data | Left Align | Center Align | Right Align |
| Column 1 | Left | Center | Right |
| First Column | Information | Data | 3.14 |
vertical-alignment classes |
top | middle | bottom |
| Last Row | 2 | Entry | .14 |
| Pre Sum | Pre Sum | Pre Sum | Pre Sum |
| Sum | Sum | ||
Multiple <tbody> sections.
Notice that the zebra striping resets with each new <tbody> section.
This is a function of the browser, and can't be solved with CSS.
| Table with Multiple Body Sections | |||
|---|---|---|---|
| Left Column | Column number 2 | Column 3 | 143.62 |
| Column 1 | Column 2 | Data | 2,684.12 |
| Uno | Two | Three | 721.53 |
| One Column | Second Column | Center | 3.14 |
| Last Row | 2 | Entry | .14 |
| Any Column | Next Column | In the middle | 4.15 |
| Final Row | 4 | Output | 11, 29, 1 |
| Sum | Sum | Sum | Sum |
Add the class wideGutter to make gutters wider (useful for tight columns with numbers next to each other
| Wide Gutters | |||
|---|---|---|---|
| Style | OH | OO | YTD |
| 2135 | 20 | 0 | 24 |
| 2136 | 13 | 16 | 11 |
| 2137 | 12 | 12 | 24 |
| 2138 | 29 | 10 | 38 |
| 14 | 29 | 19 | |
By comparison, here is the same table without the wideGutter class.
| Wide Gutters | |||
|---|---|---|---|
| Style | OH | OO | YTD |
| 2135 | 20 | 0 | 24 |
| 2136 | 13 | 16 | 11 |
| 2137 | 12 | 12 | 24 |
| 2138 | 29 | 10 | 38 |
| 14 | 29 | 19 | |
Vertical padding can be achieved by applying the padded class to any <tr> element.
The
paddedclass is best used in combination withbodyGroupHeadandbodyGroupFootclasses described below.
| Padded (vertically) | |||
|---|---|---|---|
| Puppets | |||
| T-Rex | 20 | 0 | 24 |
| Hedge Hog + – | 13 | 16 | 11 |
| Dogcatcher + – | 12 | 12 | 24 |
| Games | |||
| Tac-Dex + – | 29 | 10 | 38 |
| Ratuki + – | 29 | 10 | 38 |
| Total: | 19 | ||
This table has a full grid between cells by applying the grid class to the <table> element.
Standard rowspans, colspans, and notes are also demonstrated.
Apply the notes class to the <tr> element.
notes rows must be inside <tbody> (not inside <tfoot>)
| Properties | Style | Price | |
|---|---|---|---|
| Old | New | ||
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Nested as a row within the tbody along with content rows: Some fun notes! |
|||
| Unique tbody: Here are some notes related to this table of data. Oh joy! |
|||
| Assorted | $123.45 | ||
Borders can be manually removed as desired.
- Generally, row borders are applied to the top of each
<tr>. - Generally, column borders are applied to the right of each
<td>.
Apply the following classes as needed:
borderLeftborderRightnoBorderLeftnoBorderRightnoBorderTop
There is not a
borderTopclass because it is always present on rows without a specific class. Remove the top border from the row if desired.
| Properties | Style | Price | |
|---|---|---|---|
| Old | New | ||
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Assorted | $123.45 | ||
Borders can be added manually too.
The border above "old" and "new" was not added. It is a foundational CSS setting in tableListing.css applied to all rows.
| Properties | Style | Price | |
|---|---|---|---|
| Old | New | ||
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Assorted | $123.45 | ||
Zebra stripe classes are:
- default: no class declaration (pale green)
noRow(pink)voidRow(faded grey)yesRow(green)alertRow(amber)observeRow(purple)disableHighlight(default pale green, with no highlight)
Apply the desired class to the <tr> element.
On default zebra stripe rows, highlighting can be disabled by applying the class disableHighlight to the <tr> element.
Highlighting can not be disabled on colored rows.
See all zebra stripes
| Properties | Style | Price | |
|---|---|---|---|
| Regular | Rows | Default Zebra Stripes | 12.99 |
| Regular | Rows | Default Zebra Stripes | 12.99 |
| noRow | Rows | Pink Zebra Stripes & Red Text | -9.99 |
| noRow | Rows | Pink Zebra Stripes & Red Text | -3.49 |
| voidRow | Rows | Faded grey | 0 |
| voidRow | Rows | Faded grey | 0 |
| Violet Rows | Violet Zebra Stripes | Violet Row special highlight | 3.50 |
| Violet Rows | Violet Zebra Stripes | Violet Row special highlight | 3.50 |
| Violet Rows | Violet Zebra Stripes | Violet Row special highlight | 3.50 |
| Violet Rows | Violet Zebra Stripes | Violet Row special highlight | 3.50 |
| Regular Rows | Compare to Regular | Nothing special | 79.99 |
| Green Rows | Green Zebra Stripes | Green Row special highlight | 3.50 |
| Green Rows | Green Zebra Stripes | Green Row special highlight | 3.50 |
| Green Rows | Green Zebra Stripes | Green Row special highlight | 3.50 |
| Green Rows | Green Zebra Stripes | Green Row special highlight | 3.50 |
| Regular Rows | Compare to Regular | Nothing special | 79.99 |
| Amber Rows | Amber Zebra Stripes | Amber Row special highlight | 3.50 |
| Amber Rows | Amber Zebra Stripes | Amber Row special highlight | 3.50 |
| Amber Rows | Amber Zebra Stripes | Amber Row special highlight | 3.50 |
| Amber Rows | Amber Zebra Stripes | Amber Row special highlight | 3.50 |
| Regular Rows | Compare to Regular | Nothing special | 79.99 |
| Pink Rows | Pink Zebra Stripes | Pink Row special highlight | 3.50 |
| Pink Rows | Pink Zebra Stripes | Pink Row special highlight | 3.50 |
| Pink Rows | Pink Zebra Stripes | Pink Row special highlight | 3.50 |
| Pink Rows | Pink Zebra Stripes | Pink Row special highlight | 3.50 |
| Regular Rows | Compare to Regular | Nothing special | 79.99 |
| Disabled Highlight | Hover | has no effect | 1.00 |
| Disabled Highlight | Hover | has no effect | 1.00 |
| Assorted | $123.45 | ||
This table has faux head and foot rows for each <tbody> group.
In this example, there is a <tbody> section for each school.
<tbody><tbody>
<tr class='bodyGroupHead'>
<td colspan='5'>Mountain School</td>
</tr>
...
<tr class='bodyGroupFoot'>
<td colspan='5'>Total Due</td>
</tr>
</tbody>
Additionally, each row has faux head <th> and foot <class='rfoot'> columns.
In this example, the date is highlighted as a row heading, and the balance is highlighted as a row footer.
<th> (instead of <td>)Or assign class rhead to a td
<td class='rhead'><td class='rfoot'><tr>
<th>faux heading column</th>
<td>normal</td>
<td>normal</td>
<td class='rfoot'>faux foot column</td>
</tr>
* Highlighting has been disabled on the first row to show that disableHighlight works with faux head and foot columns.
Padding has been applied to bodyGroupHead and bodyGroupFoot rows in this example.
| Date | CU # | Invoice | Amount | Balance |
|---|---|---|---|---|
| The PEAK School | ||||
| * 1-Oct-2013 | 1 | 100 | 12.34 | 12.34 |
| 16-Oct-2013 | 2 | 300 | 135.79 | 148.79 |
| 18-Oct-2013 | 3 | 400 | 246.80 | 394.93 |
| $394.93 | ||||
| Mountain School | ||||
| 2-Oct-2013 | 7 | 200 | 864.20 | 864.20 |
| 31-Oct-2013 | 7 | 600 | 456.78 | 1,320.98 |
| $1,320.98 | ||||
| 15-Apr-2021 | - rfoot | 700 | 9.12 | 3,210.89 |
| 20-Mar-2021 | - rfoot | 700 | 9.12 | 3,210.89 |
| 29-Nov-2021 | - rfoot | 700 | 9.12 | 3,210.89 |
| $1,715.91 | ||||
A note about rowspans and row highlighting:
Row highlighting works with rowspans; however, each rowspan group must be separated into a distinct <tbody> section.
In this example, notice how the first section works properly,
but the last section incorrectly triggers the rowspan highlight when the last row (without any rowspans) is hovered.
| A Table with 4 Columns | |||
|---|---|---|---|
| L Column 1 | C Column 2 | R Column 3 | R Column 4 |
| Left Value | Center Value | Random Value | Right Value |
| Center Value | Random Value | Right Value | |
| Center Value | Random Value | Right Value | |
| Left Value | Center Value | Random Value | Right Value |
| Left Value | Center Value | Random Value | Right Value |
| Left Value | Center Value | Random Value | Right Value |
| Center Value | Random Value | ||
| Should have | closed tbody | after this row | |
| foobar | triggers | rowspan | highlights |
| Pre Sum | Pre Sum | Pre Sum | Pre Sum |
| Sum | Sum | Sum | Sum |
Row Highlighting is not printed, and it is only supported within <tbody>.