Template:Static row numbers
I18n/Uses TemplateStyles | I18n/Uses TemplateStyles |
This template adds a column of row numbers to a table. The numbers do not sort with the rest of the table, remaining static. Optional classes are provided to display a column label or disable numbers on specific rows.
It works on desktop and mobile versions of Wikipedia pages. It works with wikitable, sortable, and plain tables, although the implementation may differ slightly.
Usage[change]
Include this template above the table and add the static-row-numbers
class to the table start wikitext. Note, other classes such as wikitable
and sortable
are frequently added to data tables, as {| class="class1 class2"
.
Wikitext: <syntaxhighlight lang=wikitext>
</syntaxhighlight>CSS | This template uses TemplateStyles:
|
This template (re)enables row hover highlighting via wikitable class modifier mw-datatable.
How to use[change]
Just add {{row hover highlight}}
(or {{mw-datatable}}
), in any side before table with the class mw-datatable. For example:
- <syntaxhighlight lang="wikitext">
</syntaxhighlight>
For more information: Help:Table#mw-datatable – row highlighting via cursor hover. White background
Table class | Summary |
---|---|
static-row-numbers | Required. Displays a column of row numbers. Requires at least one header row. |
static-row-header-text | Displays "No." text in column label. |
static-row-header-hash | Displays hash ("#") symbol in column label. |
CSS | This template uses TemplateStyles:
|
This template (re)enables row hover highlighting via wikitable class modifier mw-datatable.
How to use[change]
Just add {{row hover highlight}}
(or {{mw-datatable}}
), in any side before table with the class mw-datatable. For example:
- <syntaxhighlight lang="wikitext">
</syntaxhighlight>
For more information: Help:Table#mw-datatable – row highlighting via cursor hover. White background
Row class | Summary |
---|---|
static-row-header | Disables a row number. Disables borders between consecutive row usages (simulates rowspan ). Add to sorttop and sortbottom rows. Add to header rows, but not needed on sortable tables and not needed on first row of borderless tables (plain tables).
|
static-row-numbers-norank | Disables a row number. Maintains borders between consecutive row usages. Optionally add to data rows. |
Used with wikitable and sortable[change]
A sortable table does not need the static-row-header
class added to header rows, but it is needed on rows that use the sorttop
or sortbottom
class, described at #Disable number on specific rows.
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-2>
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
</syntaxhighlight>
Produces:
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Used with wikitable[change]
A non-sortable table requires at least one row of column headers for the numbers to display properly.
Multiple header rows in a non-sortable table with cell borders (example, uses wikitable
class) should have the static-row-header
class added to all header rows below the first one. Add the class to the first row to remove its border and simulate a rowspan
. More info at #Disable number on specific rows.
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-2,6>
... </syntaxhighlight>Produces:
Color | Data | ||
---|---|---|---|
A | B | C |
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-3,6>
... </syntaxhighlight>Produces:
Color | Data | ||
---|---|---|---|
A | B | C |
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Used with sortable[change]
A sortable table does not need the static-row-header
class added to header rows, but it is needed on rows that use the sorttop
or sortbottom
class, described at #Disable number on specific rows.
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-2>
... </syntaxhighlight>Produces:
Color | Data | ||
---|---|---|---|
A | B | C |
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Used with plain tables[change]
A non-sortable table requires at least one row of column headers for the numbers to display properly.
Multiple header rows in a non-sortable table without cell borders (example, not using wikitable
class) should have the static-row-header
class added to all header rows except the first one, described at #Disable number on specific rows.
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-2,6>
... </syntaxhighlight>Produces:
Color | Data | ||
---|---|---|---|
A | B | C |
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Display "No." text in column label[change]
To display the "No." text in the number column's header (label), add the static-row-header-text
class to the table start wikitext.
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-2>
... </syntaxhighlight>Produces:
Color | Data | ||
---|---|---|---|
A | B | C |
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Display hash ("#") symbol in column label[change]
To display a hash ("#") symbol in the number column's header (label), add the static-row-header-hash
class to the table start wikitext.
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-2>
... </syntaxhighlight>Produces:
Color | Data | ||
---|---|---|---|
A | B | C |
Color | Data | ||
---|---|---|---|
A | B | C | |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Disable number on specific rows[change]
This section details how to disable numbers on specific rows by adding either the static-row-header
or static-row-numbers-norank
class to the row wikitext.
The static-row-numbers-norank
class can be added to data rows to disable the number.
The static-row-header
class disables the number and border between other rows that use this class consecutively, simulating a rowspan
(see Help:Table#Colspan and rowspan). This class is not needed on header rows when the table uses the sortable
class. It should be added to:
- Rows using the
sorttop
orsortbottom
class. - Header rows on non-sortable tables that have cell borders (example, uses
wikitable
class). - Header rows excluding the first on non-sortable tables that have no cell borders (plain tables; example, not using
wikitable
class).
Note, the sorttop
or sortbottom
class is added to a row so it stays at the top or bottom of a sorted list, per Help:Sortable tables.
Wikitext: <syntaxhighlight lang="wikitext" highlight=1-2,8,10,14,16,20,22>
Color | Data | ||
---|---|---|---|
A | B | C | |
Min | 1 | 2 | 3 |
Max | 10 | 11 | 12 |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Blue | 10 | 11 | 12 |
Total | 22 | 26 | 30 |
Average | 5.5 | 6.5 | 7.5 |
</syntaxhighlight>
Produces:
Color | Data | ||
---|---|---|---|
A | B | C | |
Min | 1 | 2 | 3 |
Max | 10 | 11 | 12 |
Red | 1 | 2 | 3 |
Lime | 4 | 5 | 6 |
Gold | 7 | 8 | 9 |
Blue | 10 | 11 | 12 |
Total | 22 | 26 | 30 |
Average | 5.5 | 6.5 | 7.5 |
Redirects[change]
- {{Srn}}
- {{Fixed row numbers}}
See also[change]
- {{Row numbers}} - Alternative method to add row numbers that are sortable and adjust when rows are deleted/inserted.
- Help:Sortable tables#Maintaining tables sorted alphabetically or by rank
- {{Sorting row}} - Adds a sorting row; not usable with
data-sort-type
attribute. - {{Sticky header}} - Makes column headers stick to the top of the page while scrolling through table data. When a table uses both {{Static row numbers}} and {{Sticky header}} then the use of
sorttop
andsortbottom
classes is more complex. See the examples using this template.