Template:Static column begin

Template documentation[view] [edit] [history] [purge]

A template for easily creating a numbered static column to the left of a sorted table. The template also automatically sets the following hidden category:

Note: Also remember to end the static column with {{end}} (see example below).

RedirectsEdit

  • {{Rank}}
  • {{Ranked}}
  • {{Rows}} - if you use this redirect, don't forget the "rows" parameter, too.

UsageEdit

{{Rank}} redirects to {{Static column begin}}

{{Rank
| rows=
| header-text=
| header-lines=
| header-height=
| header-padding=
| header-valign=
| row-height=
| row-header=
| text-align=
| caption=
}}
<!-- Your sorted table code here -->
{{End}} <!-- Don't forget to add this after your table code! -->

ParametersEdit

Only the "Rows" parameter is currently obligatory. It has no default value, and not specifying that value will break the static row column.

Rows
The number of rows in the column. This must be between 0 and 1050. Can also use Template:Table row counter {{TRC}}. See its documentation.
Header-text
The text to show in the row-number column header. The default is no text.
Header-lines
For example; header-lines=2. This maintains row alignment. It also will allow text alone to be zoomed to very high levels without losing row alignment. For example; in Firefox browser go to view menu > zoom > zoom text only > zoom in. If there is just one line in one row, then this parameter is not needed. If there are more lines, then for this to work there must be a header cell that spans (via row-span) all the other header cells. It may need breaks added. For the number to use count the number of text and sorting lines. Add the number of header rows minus one (or count the number of solid separation lines in the header). See examples farther down.
Header-height
This is rarely needed now. The height of the row-number column header in em units. For example; header-height=14.19em. It has to be a precise number in order for rows to stay aligned. For this reason and more the header-lines parameter is much easier to use. If pixels are used header-height adds blank space to the top of the header cells.
Header-padding
This parameter is not needed, and it is currently not working even when class=wikitable and class=mw-datatable are removed from the table. The padding of the row-number column header. Add header-padding=x in pixels. For example; header-padding=2px. Don't forget to also add the same padding to the table.
Header-valign
The vertical alignment of the text in the row-number column header. Options are top, center and bottom. The default value when the row-header parameter is enabled is center, otherwise it is bottom. See the example below: "Example with row-header formatting."
Row-height
The height of each row-number cell. This is not usually necessary. This does not adjust the height of the rows in the main table.
Row-header
Enabling this (y or yes) eliminates the space between the 2 tables. It also centers the row-number header text vertically. It makes the background of row number cells darker in order to match the background of the header row. See the example below: "Example with row-header formatting."
Text-align
Text alignment of the row numbers. Options are left, center and right. The default value is right.
Caption
Allows you to specify a caption to appear over the combined table.

Visual Editor and this template. Must add nowiki tags temporarilyEdit

Use the wikitext editor first. WP:Visual Editor (VE) will not work until the {{Rank}} line has nowiki tags added around it first in the wikitext. Or hidden comment tags <!-- -->.

See Phabricator: T245277. It is titled "VE can't edit tables nested inside a transcluded table (example: row number single-column table from {{Rank}} on English Wikipedia".

ExampleEdit

{{Rank}} redirects to {{Static column begin}}

Code
<!-- Static column begin -->
{{Rank |rows=2 |header-text=Number |text-align=center}}
<!-- Sorted table start -->
{| class="wikitable nowrap sortable mw-datatable"
!Country
!Capital
|- 
|The Netherlands || Amsterdam (although The Hague is the seat of government)
|- 
|France || Paris
|}
<!-- Sorted table end -->
{{End}}
Resulting table
Number
1
2
Country Capital
The Netherlands Amsterdam (although The Hague is the seat of government)
France Paris
class=nowrap

Note that the nowrap class in the table header means that the rows will not ladder in narrow screens such as cell phones, tablets, etc.. So row alignment is maintained. You can test this right now in your browser by narrowing the browser window. Drag the sides of the browser window and narrow it as much as needed to see this.

class=mw-datatable

This highlights rows as the mouse hovers over them. This is helpful for quickly scanning rows, looking up at the headers, and not losing one's place.

Example with row-header formattingEdit

Enabling this (row-header=y or row-header=yes) eliminates the space between the 2 tables. It also centers the row-number header text vertically. It makes the background of row number cells darker in order to match the background of the header row.

Code
<!-- Static column begin -->
{{Rank |rows=2 |header-text=Number |row-header=y |text-align=center}}
<!-- Sorted table start -->
{| class="wikitable nowrap sortable mw-datatable"
!Country
!Capital
|- 
|The Netherlands || Amsterdam (although The Hague is the seat of government)
|- 
|France || Paris
|}
<!-- Sorted table end -->
{{End}}
Resulting table
Number
1
2
Country Capital
The Netherlands Amsterdam (although The Hague is the seat of government)
France Paris

Header-lines. Example with multi-row headersEdit

This is taken from a version of List of U.S. states and territories by incarceration and correctional supervision rate.

header-lines=5 is what is needed in this case to allow text-only zooming to very high levels. The left-most header cell spans the other header cells, and it is spanning 4 lines of text, and 1 border line. For a total of 5 lines. Note in the wikitext that breaks <br> are added to that spanning cell so that there are 5 lines in it. valign=bottom is added so that the header text is next to the bottom of the header cells.

Below is the header wikitext:

{{Rank|rows=2|header-lines=5|caption=Correctional supervision rates by state, 2016.}}
{|class="wikitable nowrap sortable mw-datatable" style=text-align:right; id="states"
|- valign=bottom
! rowspan=2|<br><br><br><br>Jurisdiction!! colspan=2|Total !! colspan=2|Community supervision || colspan=2|Incarcerated
|-

It produces:

Correctional supervision rates by state, 2016.





1
2




Jurisdiction
Total Community supervision Incarcerated
Total,
12/31/2016
Rate per
100,000
adults
Probation
or Parole,
12/31/2016
Rate per
100,000
adults
In prison
or jail,
12/31/2016
Rate per
100,000
adults
 Alabama 99,800 2,640 60,700 1,610 40,900 1,080
 Alaska 12,900 2,320 8,400 1,520 4,400 800

Header-lines. Example of a very wide table made narrower with a multi-row headerEdit

Note to developers and template editors: There has to be an easier way. Please create it. Someone with Phabricator clout and understanding might know where and how to suggest on Phabricator that the sorting icon be put on the top or bottom instead of on the side. The header cells would be narrower, and there would be no need for a separate row of sorting cells.

Table made narrower by adding a separate row of sorting cells.


Life expectancy at birth (both genders)

1
2
Country 1543 1683 1771 1810 1830 1851 1860 1870 1882 1890 1895 1900 1905 1910 1915 1920 1925 1930 1935 1940 1949
Australia 52.95 57.00 59.32 63.16 64.89 65.09 66.29 69.13
Austria 34.40 34.40 41.73 63.42

Row of sorting cells added to narrow the table:
|-
!<br>!! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !! !!

The country header has rowspan=2 added to it. And some breaks are added to the country header so that it has as many lines as are in the other headers. Each break counts as a line. Borders between header rows count as lines for this calculation.

!rowspan=2|<br><br>Country

header-lines=3 is added as a {{Rank}} parameter to allow text-only zooming to very high levels without losing row alignment.


Life expectancy at birth (both genders)



1
2


Country
1543 1683 1771 1810 1830 1851 1860 1870 1882 1890 1895 1900 1905 1910 1915 1920 1925 1930 1935 1940 1949

Australia 52.95 57.00 59.32 63.16 64.89 65.09 66.29 69.13
Austria 34.40 34.40 41.73 63.42

Example with complex multi-row headersEdit

Note to developers and template editors: There has to be an easier way to keep rows aligned. Please create it. Please reinvigorate Phabricator T42618. jquery.tablesorter: Add support for a "fixed" column of row numbers. One stalled patch there kept rows aligned even with row laddering.

This is about keeping the rows aligned between the fixed row number column and the table to its right. {{Static column begin}} does this best when there is a column header in the main table that spans all the header rows.

Sometimes you have to create that row-spanning header cell. For example; see the top table in this specific revision of a Wikipedia article.

The blank row-spanning header cell and column has been added on the right side:

Incarceration rates by state.









Row
1
2
Jurisdiction Year-end
2016. In
prison
or jail
2016
rate per
100,000
adults
2016
rate per
100,000
of all ages










US total 2,131,000 850 660
Federal 188,400 80 60
States, and
District of Columbia
1,942,600 780 600
 Alabama 40,900 1,080 840
 Alaska 4,400 800 600

header-lines=10 allows readers to zoom the text alone to very high levels and not break row alignment. For example; in Firefox browser go to:
view menu > zoom > zoom text only > zoom in.

The blank column is made invisible by adding style="padding-left:0;padding-right:0;" to its header.

Incarceration rates by state.









Row
1
2
Jurisdiction Year-end
2016. In
prison
or jail
2016
rate per
100,000
adults
2016
rate per
100,000
of all ages










US total 2,131,000 850 660
Federal 188,400 80 60
States, and
District of Columbia
1,942,600 780 600
 Alabama 40,900 1,080 840
 Alaska 4,400 800 600

Here is how that empty row-spanning header is formatted so that header-lines=10 works:
!rowspan=4 class=unsortable style="padding-left:0;padding-right:0;"|<br><br><br><br><br><br><br><br><br><br>

Here is the header wikitext:

{{Rank| rows=2| header-text=Row| header-lines=10| text-align=right| caption=Incarceration rates by state.}}
{|class="wikitable nowrap sortable mw-datatable" border=1 style=text-align:right; 
|-valign=bottom
 !Jurisdiction
 !Year-end<br>2016. In<br>prison<br>or jail
 !2016<br>rate per<br>100,000<br>adults
 !2016<br>rate per<br>100,000<br>of all ages
 !rowspan=4 class=unsortable |<br><br><br><br><br><br><br><br><br><br><!--The spanning header cell is needed for {{Rank}} row alignment.-->
|-

See alsoEdit