Jump to content

User:Timeshifter/Sandbox228

From Wikipedia, the free encyclopedia

Problem with class=sorttop

[edit]

class=sorttop rows can become part of the sticky header. This only happens after sorting.

This table excerpt is adapted from the 2021 table in this version of COVID-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.

class=static-row-header prevents row numbers on those rows.
class=sorttop prevents the row from sorting.

See the yellow highlighted lines in the wikitext below.

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

Solution for single row header

[edit]

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

class=sticky goes in a different part of the wikitext.

See the yellow highlighted line in the wikitext below.

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
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
 USA March 3, 2020 335,789 436,051 508,584 545,887 569,722 588,756
 Brazil March 19, 2020 193,875 223,945 254,221 317,646 401,186 461,931
 India 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
...
|}

Solution for single row header. Narrower table

[edit]

See: User:Timeshifter/Sandbox233. A place to test if it works without a wider table on the page.

Cumulative COVID-19 deaths at the start of each month in 2021
Date First case Jan 1
World 1,472,363
Days to double 112
Countries and territories 196
 USA March 3, 2020 335,789
 Brazil March 19, 2020 193,875
 India 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:

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|