Help:Sortable tables: Difference between revisions

Content deleted Content added
note about mobile app problem
 
(5 intermediate revisions by 4 users not shown)
Line 5:
{{Wiki markup}}
{{TOC limit|3}}
 
{{hatnote|'''Note:''' Tables are sortable in mobile browsers, but not in the [[wikipedia mobile app|mobile app]]. See [[phab:T181452]].}}
 
== Creating sortable tables ==
Line 704 ⟶ 706:
Table below is an adapted excerpt from [[List of U.S. states and territories by poverty rate]]. '''Sorttop''' is used on the US data row. And the US row is excluded from having a static row number. Note that the "Area" flag links can't be made bold the normal way. But the whole row can be made bold like this:
 
<syntaxhighlight lang=wikitext highlight=1>
|- class="sorttop static-row-numbers-norank" style="font-weight:bold;"
| {{flagg|uspeft|pref=Economy of|United States}}
| 12.5 || 0.1 || 40,763,043 || 277,214
</syntaxhighlight>
 
Line 711 ⟶ 715:
{| class="wikitable sortable sticky-header mw-datatable col1left static-row-numbers" style=text-align:right;
|+ Number and percentage of people in poverty by state, D.C., and Puerto Rico. Plus margin of error. 2023.
! Area !! Percent !! Error (±) !! Number !! Error (±)
! Area
! Percent
! Error (±)
! Number
! Error (±)
|- class="sorttop static-row-numbers-norank" style="font-weight:bold;"
| {{flagg|uspeft|pref=Economy of|United States}}
| 12.5 || 0.1 || 40,763,043 || 277,214
| 12.5
| 0.1
| 40,763,043
| 277,214
|-
| {{flagg|uspeft|pref=Economy of|Puerto Rico}}
| 39.6 || 0.8 || 1,257,607 || 26,856
| 39.6
| 0.8
| 1,257,607
| 26,856
|-
| {{flagg|uspeft|pref=Economy of|Louisiana}}
| 18.9 || 0.6 || 840,146 || 27,162
| 18.9
| 0.6
| 840,146
| 27,162
|-
| {{flagg|uspeft|pref=Economy of|Mississippi}}
| 18.0 || 0.8 || 512,184 || 21,949
| 18.0
| 0.8
| 512,184
| 21,949
|}
 
Line 748 ⟶ 736:
 
== Forcing a column to have a particular data type ==
{{See|metamediawikiwiki:Help:SortingSortable tables#Forcing the sort mode forof a column}}
 
The <code>data-sort-type="..."</code> attribute can be added inside the header of a column to ensure that the cells underneath are ''all'' treated as a specified type of data. {{A note|It must go in the header cell with the sorting icon}}. It will not work in a header cell without a sorting icon. For example; when there are two rows of headers, the bottom row will always have the sorting icons, as explained previously. If there are problems sorting a column, forcing a particular data type often helps. Be specific. If the column is currency, force that data type, not number.