Template:Sticky table start - Wikipedia


Article Images

This template adds a scrollable container around a table and its classes can be used to make the table's rows stick to the top or the columns stick to the left side of the container as the table's data is scrolled in and out of view.

It's used on tall and/or wide tables that have headers that might be difficult to remember as you scroll through the data. It keeps very wide tables within the main content area's width so the layout of Wikipedia's desktop version remains intact.

A toggle button displays on smaller screens to disable or enable these features for cases where large sticky elements are a hindrance to reading the underlying scrollable data, which is more likely on small devices such as mobile phones.

Usage

Include {{sticky table start}} above and {{sticky table end}} below the table. Add any of the following as needed.

Table classes

Classes for table start wikitext: {| class="class1 class2".
Class Summary
sticky-table-head Make the table head top sticky. Don't combine with sticky-table-rowN. Requires sortable table, which moves consecutive top header rows into the <thead> (table head) HTML element. Rows using the sorttop class become sticky after sorting (issue: T355492). Avoid making headers sticky that aren't for the entire table (ex. section header rows). Avoid making excessively tall header rows sticky that might block too much data on short screens (ex. mobile landscape).
sticky-table-rowN Make row N top sticky where N is a number from 1 to 2. Limit 1 to avoid stacking issues where a taller row 1 is still visible. Don't combine with sticky-table-head. Unpredictable results if the row spans or is spanned with the rowspan attribute.
sticky-table-colN Make column N left sticky where N is a number from 1 to 2. Limit 1 to avoid stacking issues where a wider column 1 is still visible. Unpredictable results if the column spans or is spanned with the colspan attribute. Avoid making an excessively wide column sticky that might block too much data on narrow screens (ex. mobile portrait).

Cell classes

Classes for cell wikitext: ! class="class1 class2" | …
or | class="class1 class2" | ….
Class Summary
sticky-table-none Remove sticky from cell in cases where rowspan causes an issue. For example, a sticky column using rowspan will have some cells that are sticky in the next column. See usage example. Usage search.
sticky-table-left Add left sticky to cell in cases where rowspan causes an issue. For example, column 1 using rowspan with a sticky column 2 will have some cells in column 2 that are not sticky and some in column 3 that are sticky. See usage example. Usage search.

Sticky row 1 and column 1

Note: Also works if the table uses the sortable class.

{{Sticky table start}}
{| class="wikitable sticky-table-row1 sticky-table-col1"|}
{{Sticky table end}}

Sticky head and column 1

Note: The sticky-table-head class requires the table to use the sortable class so the column header rows are moved to the <thead> element.

The "Header 2" cell uses the sticky-table-none class to fix the left sticky issue caused by the "Header 1" cell's rowspan.

{{Sticky table start}}
{| class="wikitable sortable sticky-table-head sticky-table-col1"
|+ Caption
|-
! rowspan="2" | Header 1
! colspan="4" | Header group 1|-
! class="sticky-table-none" | Header 2
! Header 3 !! Header 4 !! Header 5 !!|}
{{Sticky table end}}

Usage of sticky-table-none and sticky-table-left

The header rows are top sticky and the second column is left sticky. When making a column left sticky and rowspan messes up what is sticky, the sticky-table-none and sticky-table-left classes can be used to fix it.

For illustration purposes, background colors have been added to the table:

  • yellow for sticky-table-none
  • orange for sticky-table-left
{{Sticky table start}}
{| class="wikitable sortable sticky-table-head sticky-table-col2"
|-
! rowspan="2 | Header 1
! rowspan="2" | Header 2
! colspan="3" | Header group 1 !!
|-
! Header 3
! class="sticky-table-none" | Header 4
! Header 5 !!
|-
| data
| rowspan="2" | data
| data |||-
| data
| class="sticky-table-none" | data
| data |||-
| rowspan="2" | data
| data |||-
| class="sticky-table-left" | data
| class="sticky-table-none" | data
| data || …
⫶
|}
{{Sticky table end}}

Example with sticky head and column 1

Adapted from this version of List of U.S. state and territory abbreviations § Table.

The column 1 "Name" and column 2 "Status of region" cells in row 1 use rowspan to span into row 2. When making column 1 left sticky, this makes the first cell in row 2, the empty sorting cell under "ISO", left sticky, so the sticky-table-none class is added to that cell.

{{sticky table start}}{{mw-datatable}}
{|class="wikitable sortable sticky-table-head sticky-table-col1 mw-datatable"
|+ Codes and abbreviations for U.S. states, federal district, territories, and other regions
! rowspan=2 | [[List of states and territories of the United States|Name]]
! rowspan=2 | Status of region
! [[ISO 3166|ISO]]
! colspan=2 | [[#ANSI standard INCITS 38:2009|ANSI]]
! [[#Postal codes|USPS]]
! [[#Coast Guard vessel prefixes|USCG]]
! rowspan=2 | [[#GPO|GPO]]
! rowspan=2 | [[#Current use of traditional abbreviations|AP]]
! rowspan=2 | Other<br>abbreviations
|-
! class=sticky-table-none | !! !! !! !! &nbsp;
|}
{{sticky table end}}

Example with sticky row 2 and column 2

Adapted from WTA 1000 Series singles records and statistics § Title leaders.

Note: The column 1 "Titles", "Player", and "Years" cells have their rowspan removed and the cells moved from row 1 to row 2 to facilitate making row 2 top sticky. Because row 1 is hidden when row 2 is sticky, the other cells in row 2 have a background color to visually relate them to the "Active tournaments" and "Defunct tournaments" parent cells in row 1. The two cells in row 1 are kept for screen readers instead of moving them to a legend. Doing this helps reduce the amount of top sticky content: 1 row instead of 2.

The "10", "9", "6", and "5" cells in the "Titles" column 1 use rowspan. When making column 2 left sticky, cells in the spanned rows have column 2 not left sticky and column 3 left sticky, so the sticky-table-left and sticky-table-none classes are added to those column 2 and column 3 cells, respectively.

{{mw-datatable}}{{sort under}}{{sticky table start}}
{| class="wikitable mw-datatable sortable sort-under-center sticky-table-row2 sticky-table-col2" style="text-align:center"
|-
! scope="row" rowspan="3" |10
|style="text-align:left" | {{sort|Henin.|{{flagg|uxx|BEL}} [[Justine Henin]]}}
| -
| -
⫶
|-
|style="text-align:left; background-color:#FFFFE0;" class="sticky-table-left" | {{sort|Azarenka.|{{flagg|uxx|BLR}} '''[[Victoria Azarenka]]'''}}*
| class="sticky-table-none" | -
| style="background-color:#B9FF72;" |2*
⫶
|-
|style="text-align:left; background-color:#FFFFE0;" class="sticky-table-left" | {{sort|Świątek.|{{flagg|uxx|POL}} '''[[Iga Świątek]]'''}}*
| class="sticky-table-none" | -
| style="background-color:#B9FF72;" |2*
⫶
|}
{{sticky table end}}

*  Active players.

*  Most titles won per tournament.

Note: The asterisks (*) are used because screen readers can not see cell background colors.

Note: In article namespace the links in colored cells are underlined black links. See:

See also

More template styles for tables: