Changes

3,282 bytes removed ,  11:01, 6 June 2007
no edit summary
Line 1: Line 1: −
{{H:h}}
+
[[Help:Table|Tables]] can be made sortable via [[client-side JavaScript|client-side JavaScript]] with <code>class="sortable"</code>. Sortable tables are identified by the arrows in each of its header cells. Clicking them will cause the table rows to sort based on the selected column, in ascending order first, and subsequently toggling between ascending and descending order. Links and other wiki-markup are not possible in headers.
[[Help:Table|Tables]] can be made {{mlw|sorting||sortable}} via [[w:client-side JavaScript|client-side JavaScript]] with <code>class="sortable"</code>. This works in MediaWiki 1.9, which is installed in all Wikimedia projects. Sortable tables are identified by the arrows in each of its header cells. Clicking them will cause the table rows to sort based on the selected column, in ascending order first, and subsequently toggling between ascending and descending order. Links and other wiki-markup are not possible in headers.
  −
 
  −
Note that all of the below is subject to change due to improvements in the script.
  −
 
  −
==Javascript==
  −
The JavaScript code [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/skins/common/wikibits.js?view=log wikibits.js] has on each site a copy at
  −
<nowiki>{{SERVER}}/skins-1.5/common/wikibits.js</nowiki>, on this site {{SERVER}}/skins-1.5/common/wikibits.js. In addition a site may have a page [[MediaWiki:Common.js]] which adds and overrides some code. The description below applies to the version on Meta, {{mlm|MediaWiki:Common.js}}. The sorting code in it can be copied to other sites (by sysops of these other sites).
      
==Sort modes==  
 
==Sort modes==  
The sort modes (the [[w:data type|data type]]s, which, in addition to the choice "ascending" or "descending", determine the sorting order) are as follows; in the given order (as soon as there is a match, subsequent criteria are not applicable, e.g., 24-12-2007 is a date, not a number. For the criteria, tags (e.g. span, sup, sub) are ignored.
+
The sort modes (the [[data type|data type]]s, which, in addition to the choice "ascending" or "descending", determine the sorting order) are as follows; in the given order (as soon as there is a match, subsequent criteria are not applicable, e.g., 24-12-2007 is a date, not a number. For the criteria, tags (e.g. span, sup, sub) are ignored.
 
*date (see also below)
 
*date (see also below)
 
**criterion: the first non-blank element is of the form "dd-dd-dddd", "dd-dd-dd", or "dd aaa dddd"; or, in the last case, text follows ending with "sm=d" (without the quotes; it stands for "sort mode = date"). (In  hidden form this can conveniently be done with {{tim|smd}}.)
 
**criterion: the first non-blank element is of the form "dd-dd-dddd", "dd-dd-dd", or "dd aaa dddd"; or, in the last case, text follows ending with "sm=d" (without the quotes; it stands for "sort mode = date"). (In  hidden form this can conveniently be done with {{tim|smd}}.)
Line 27: Line 20:     
==Examples==
 
==Examples==
:''Remember that the results depend on fixes and enhancements in [[MediaWiki:Common.js]]; the description  applies to the version on Meta. Copies of this help page on other sites are useful for comparison. A sysop can copy the JavaScript-code from Meta.''
  −
   
Text after a number (e.g. a footnote) does not affect the sorting order, if the sorting ''mode'' is numeric. However, if the number at the top has text after it, this makes the sorting mode alphabetic, unless it ends with a (typically invisible) "sm=n".  
 
Text after a number (e.g. a footnote) does not affect the sorting order, if the sorting ''mode'' is numeric. However, if the number at the top has text after it, this makes the sorting mode alphabetic, unless it ends with a (typically invisible) "sm=n".  
   Line 576: Line 567:  
|Second
 
|Second
 
|}
 
|}
  −
See also [[w:Talk:List_of_U.S._states_by_population#Sortable_Table]].
      
===Padding with zeros===
 
===Padding with zeros===
Line 838: Line 827:     
If at some point (i.e., after possible previous sorting) the form <code><nowiki>[[YYYY]]</nowiki></code> is at the top with a non-negative year, sorting would be numerical; in this case, after toggling between ascending and descending there would be no proper sorting ''within'' each year (because [http://www.devguru.com/technologies/ecmascript/QuickRef/parsefloat.html parsefloat] is applied, finding the first number in the string, and basing sorting on only that number). Also, years BC would not be sorted properly. Therefore, alphabetic sorting has to be enforced. This can be done by putting a non-displayed character after the year, separated by a space.
 
If at some point (i.e., after possible previous sorting) the form <code><nowiki>[[YYYY]]</nowiki></code> is at the top with a non-negative year, sorting would be numerical; in this case, after toggling between ascending and descending there would be no proper sorting ''within'' each year (because [http://www.devguru.com/technologies/ecmascript/QuickRef/parsefloat.html parsefloat] is applied, finding the first number in the string, and basing sorting on only that number). Also, years BC would not be sorted properly. Therefore, alphabetic sorting has to be enforced. This can be done by putting a non-displayed character after the year, separated by a space.
  −
See also:
  −
*{{tiw|dts}}
  −
*[[bugzilla:8226]].
      
==Secondary sortkey==
 
==Secondary sortkey==
Line 1,030: Line 1,015:     
The two-character entries such as A1 demonstrate that A and a are at the same position.
 
The two-character entries such as A1 demonstrate that A and a are at the same position.
  −
==See also==
  −
*{{ml|Help:Collapsing|Sortable_collapsible_table|Sortable collapsible table}}
  −
*{{tiw|dts}} - sorting a table by a date column, while following [[w:Wikipedia:Manual_of_Style_%28dates_and_numbers%29#Dates_containing_a_month_and_a_day]] for display
  −
*{{tim|sd}} - shows buggy date sorting when some or all dates are linked
  −
*[[Help:Table]]
  −
*[http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/skins/common/wikibits.js wikibits.js] - contains, among other things, the sorting code
  −
**for revision history see also [http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/skins/common/sorttable.js?view=log&pathrev=19698 sorttable.js]
  −
**{{mlm|MediaWiki:Common.js}} page overriding function ts_parseFloat(num) and function ts_resortTable(lnk) on Meta with improved versions
  −
**{{mlw|MediaWiki:Common.js}} page overriding function ts_parseFloat(num)
  −
**[[sv:MediaWiki:Common.js]] page overriding function ts_parseFloat(num); adaptation to decimal comma
  −
*[[bugzilla:2001]] - resolved feature request
  −
*[[bugzilla:8063]] - request to enable sorting of numbers with a point as thousands separator
  −
*[[bugzilla:8115]]
  −
*http://www.kryogenix.org/code/browser/sorttable/ - explanation of the original version of the code by Stuart Langridge; an improvement in the MediaWiki version is that tables no longer need to have an id.
  −
*http://blog.webkist.com/archives/000043.html
  −
*http://www.joostdevalk.nl/code/sortable-table/
  −
*[[w:Wikipedia:Wikipedia Signpost/2007-01-02/Technology report]]
  −
*{{tiw|sort}}
  −
*[[mw:Extension:Sort2]]
  −
*[[mw:Extension:Sort]]
  −
*[[w:User:TimR/Tables]]
  −
  −
Examples elsewhere:
  −
  −
*[[w:Ranked list of Dutch provinces]]
  −
*[[w:List of countries by GDP estimates for 2006 (nominal)]]
  −
*[[w:List of countries by GDP (PPP), 2006]]
  −
*[[w:List of longest reigning current monarchs]] - date columns are sortable for people with "no preference" for date formatting, and for people with preference <nowiki>[[YYYY-MM-DD]]</nowiki>.
  −
*[[w:User:Smurrayinchester/Template|Pokémon table]] - prefixes numbers with "#" to have them before "-".
  −
*[[w:Nuclear_power_by_country|Nuclear power by country]] (Featured List)
  −
*[[w:Desert Island Discs: castaways' choices]]
  −
  −
  −
  −
{{h:f|enname=Sorting}}
 
2,646

edits