Template:Static column begin/doc

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:
 * Category:Articles with tables with fixed row numbers

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

Redirects

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

Usage
Rank redirects to Static column begin

Parameters
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; . 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  ) 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; . It has to be a precise number in order for rows to stay aligned. For this reason and more the   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  and   are removed from the table. The padding of the row-number column header. Add   in pixels. For example;  . 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,   and  . The default value when the   parameter is enabled is  , otherwise it is  . 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 ( or  ) 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,   and  . The default value is.


 * Caption : Allows you to specify a caption to appear over the combined table.

Visual Editor and this template. Must add nowiki tags temporarily
Use the wikitext editor first. WP:Visual Editor (VE) will not work until the 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 on English Wikipedia".

Example
Rank redirects to Static column begin


 * Code


 * Resulting table

This highlights rows as the mouse hovers over them. This is helpful for quickly scanning rows and headers, but without losing one's place. Run your cursor over the rows in the above table to see.
 * class=mw-datatable

class=nowrap and table width
The rows will not align if the table is too wide for the screen it is viewed in. This is because the data and text in the table rows will wrap in order to fit in the screen. Narrow your browser width to see the laddering.

This is true unless  is used. See its use in the above table. But it is better to narrow the table. This way the table may fit in tablets and cell phone screens without extending past the screen.

Example with row-header formatting
Enabling this ( or  ) 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


 * Resulting table

Header-lines. Example with multi-row headers
This is taken from a version of List of U.S. states and territories by incarceration and correctional supervision rate.

  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   are added to that spanning cell so that there are 5 lines in it. is added so that the header text is next to the bottom of the header cells.

Below is the header wikitext:

{|class="wikitable nowrap sortable mw-datatable" style=text-align:right; id="states" ! rowspan=2|   Jurisdiction!! colspan=2|Total !! colspan=2|Community supervision || colspan=2|Incarcerated It produces:
 * - valign=bottom

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

 * 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.


 * A table version below from List of countries by past life expectancy

Row of sorting cells added to narrow the table:

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| Country  

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

Example with complex multi-row headers

 * 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:

 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  to its header.

Here is how that empty row-spanning header is formatted so that   works:  

Here is the header wikitext: