Help:Sorting: Difference between revisions From Online Manual

Jump to: navigation, search
(Created page with "In many situations, lists of page titles or user names are sorted alphabetically by MediaWiki. It is also possible to use JavaScript to sort lists of data that are included in p...")
 
No edit summary
 
Line 3: Line 3:
== Sort order ==
== Sort order ==


When lists are sorted {{mediawiki|w:Collation#Alphabetical order|alphabetically}} by MediaWiki, the order of characters is the same as the order of {{mediawiki|w:Unicode|Unicode}} code points.  That is, the usable character that comes first in the Unicode sequence (the space character) will be ranked highest in sorted lists; when an entry in the list begins with a space, that entry is likely to be at the top of the sorted list (unless another entry in the list begins with ''more than one'' consecutive space, of course).
When lists are sorted alphabetically by MediaWiki, the order of characters is the same as the order of Unicode code points.  That is, the usable character that comes first in the Unicode sequence (the space character) will be ranked highest in sorted lists; when an entry in the list begins with a space, that entry is likely to be at the top of the sorted list (unless another entry in the list begins with ''more than one'' consecutive space, of course).


Some more common characters are ordered as follows (in descending order):
Some more common characters are ordered as follows (in descending order):
Line 94: Line 94:


==Sorting in categories==
==Sorting in categories==
Pages in categories are sorted by their title. This can be overridden by a sort key, see [[Help:Categories#Sort_key]].
Pages in categories are sorted by their title.  


== See also ==


* [[Manual:$wgCategoryCollation]] - allows you to change the collation used for categories (requires shell access).
*{{mediawiki|b:Unicode/Character reference|Unicode character references}} on the English Wikibooks
**{{mediawiki|b:Unicode/Character reference/0000-0FFF|Initial characters}}
*{{mediawiki|m:Help:Sorting|Help:Sorting}} on Meta-Wiki
{{languages}}
[[Category:Help]]
[[Category:Help]]

Latest revision as of 15:41, 29 May 2013

In many situations, lists of page titles or user names are sorted alphabetically by MediaWiki. It is also possible to use JavaScript to sort lists of data that are included in page text.

Sort order

When lists are sorted alphabetically by MediaWiki, the order of characters is the same as the order of Unicode code points. That is, the usable character that comes first in the Unicode sequence (the space character) will be ranked highest in sorted lists; when an entry in the list begins with a space, that entry is likely to be at the top of the sorted list (unless another entry in the list begins with more than one consecutive space, of course).

Some more common characters are ordered as follows (in descending order):

!"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'
abcdefghijklmnopqrstuvwxyz{|}~
¡¢£¤¥¦§¨©ª«­®¯°±²³´µ•¸¹º»¼½¾¿
ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
ĀāĂ㥹ĆćĈĉĊċČčĎďĐđĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħĨĩĪīĬĭĮįİıIJijĴĵĶķĸĹĺĻļĽľĿŀŁłŃńŅņŇňʼnŊŋ
ŌōŎŏŐőŒœŔŕŖŗŘřŚśŜŝŞşŠšŢţŤťŦŧŨũŪūŬŭŮůŰűŲųŴŵŶŷŸŹźŻżŽžſ
ǺǻǼǽǾǿ΄΅Ά·ΈΉΊΌΎΏΐ
ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩΪΫάέήίΰ
αβγδεζηθικλμνξοπρςστυφχψωϊϋόύώ

Sorting in pages

When a list of entries is included in a table on a page, you can use JavaScript to make the table 'sortable'. To do this, just add the "sortable" class to the table declaration:

 {| class="wikitable sortable"
 |-
 ! Fruit   !! Price
 |-
 | Apples  || £0.95
 |-
 | Oranges || £0.85
 |-
 | Pears   || £1.15
 |}

Which produces the following output:

Fruit Price
Apples £0.95
Oranges £0.85
Pears £1.15

By clicking on the buttons in the cell headers, the entries can be sorted by the value in that column, in either ascending or descending order.

Specifying a sort key

Depending on the wiki, data-sort-value can be used to specify a sort key. $wgHtml5 needs to be enabled in MediaWiki, which is the case on all WMF wikis since September 2012.

Example:

{| class="wikitable sortable"
! Name and Surname
! Height
|-
|data-sort-value="Smith, John"| John Smith
| 1.85
|-
|data-sort-value="Ray, Ian"| Ian Ray
| 1.89
|-
|data-sort-value="Bianchi, Zachary"| Zachary Bianchi
| 1.72
|-
! Average:
| 1.82
|}

gives:

Name and Surname Height
John Smith 1.85
Ian Ray 1.89
Zachary Bianchi 1.72
Average: 1.82

Sorting in categories

Pages in categories are sorted by their title.



Advertisement: