class=sorttop rows can become part of the sticky header. This only happens after sorting.
This table excerpt is adapted from the 2021 tableinthis versionofCOVID-19 pandemic deaths#2021 (first half).
The static rows at the top under the main header row are rows of data that shouldn't sort, and shouldn't have row numbers.
See the yellow highlighted lines in the wikitext below.
Date | First case | Jan 1 | Feb 1 | Mar 1 | Apr 1 | May 1 | Jun 1 |
---|---|---|---|---|---|---|---|
World | 1,472,363 | 1,786,759 | 2,021,136 | 2,262,948 | 2,603,854 | 3,663,570 | |
Days to double | 112 | 105 | 113 | 130 | 143 | 154 | |
Countries and territories | 196 | 202 | 202 | 205 | 206 | 209 | |
![]() |
March 3, 2020 | 335,789 | 436,051 | 508,584 | 545,887 | 569,722 | 588,756 |
![]() |
March 19, 2020 | 193,875 | 223,945 | 254,221 | 317,646 | 401,186 | 461,931 |
![]() |
March 13, 2020 | 148,994 | 154,392 | 157,157 | 162,927 | 211,853 | 331,895 |
{{mw-datatable}}{{static row numbers}}{{sticky header}}{{table alignment}}
{| class="wikitable sortable mw-datatable static-row-numbers sticky-header col1left col2left" style=text-align:right;
|+Cumulative COVID-19 deaths at the start of each month in 2021
!Date!!First case!!Jan 1!!Feb 1!!Mar 1!!Apr 1!!May 1!!Jun 1
|- class="sorttop static-row-header"
|World || ||1,472,363||1,786,759||2,021,136||2,262,948||2,603,854||3,663,570
|- class="sorttop static-row-header"
|Days to double || ||112||105||113||130||143||154
|- class="sorttop static-row-header"
|Countries and territories || ||196||202||202||205||206||209
|-
...
This solution only works for a single row header. The number of lines in that row does not matter. This does not work for multi-row headers.
The solution is to use class=sticky instead of class=sticky-header
See the yellow highlighted line in the wikitext below.
Date | First case | Jan 1 | Feb 1 | Mar 1 | Apr 1 | May 1 | Jun 1 |
---|---|---|---|---|---|---|---|
World | 1,472,363 | 1,786,759 | 2,021,136 | 2,262,948 | 2,603,854 | 3,663,570 | |
Days to double | 112 | 105 | 113 | 130 | 143 | 154 | |
Countries and territories | 196 | 202 | 202 | 205 | 206 | 209 | |
![]() |
March 3, 2020 | 335,789 | 436,051 | 508,584 | 545,887 | 569,722 | 588,756 |
![]() |
March 19, 2020 | 193,875 | 223,945 | 254,221 | 317,646 | 401,186 | 461,931 |
![]() |
March 13, 2020 | 148,994 | 154,392 | 157,157 | 162,927 | 211,853 | 331,895 |
{{mw-datatable}}{{static row numbers}}{{sticky header}}{{table alignment}}
{| class="wikitable sortable mw-datatable static-row-numbers col1left col2left" style=text-align:right;
|+Cumulative COVID-19 deaths at the start of each month in 2021
|- class=sticky
!Date!!First case!!Jan 1!!Feb 1!!Mar 1!!Apr 1!!May 1!!Jun 1
...
|}
See: User:Timeshifter/Sandbox233. A place to test if it works without a wider table on the page.
Date | First case | Jan 1 |
---|---|---|
World | 1,472,363 | |
Days to double | 112 | |
Countries and territories | 196 | |
![]() |
March 3, 2020 | 335,789 |
![]() |
March 19, 2020 | 193,875 |
![]() |
March 13, 2020 | 148,994 |
{{mw-datatable}}{{static row numbers}}{{sticky header}}{{table alignment}}
{| class="wikitable sortable mw-datatable static-row-numbers col1left col2left" style=text-align:right;
|+Cumulative COVID-19 deaths at the start of each month in 2021
|- class=sticky
!Date!!First case!!Jan 1
...
|}
For portrait view on cell phones:
| | | | | |
| | | | | |
| | | | | |
| | | | |
| | | | | | | |
| | | | | | | |
| | | | | |
| | | | | |
| | | | | |
| | | | |
| | | | | | | |
| | | | | | | |