Help:Sorting

From mediawiki.org

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 sorted with Intl.Collator. This sorts accented characters correctly based on PageContentLanguage.

Android Webviews don't support this, so fallback to the old sort routine is required. The order is the same as the order of Unicode code points. Some of the more common characters are ordered as follows (in ascending order):

 
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C
D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g
h i j k l m n o p q r s t u v w x y z { | } ~
 
¡ ¢ £ ¤ ¥ ¦ § ¨ © ª « ¬
­
® ¯ ° ± ² ³ ´ µ · ¸ ¹ º » ¼ ½ ¾ ¿ À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð
Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô
õ ö ÷ ø ù ú û ü ý þ ÿ Ā ā Ă ă Ą ą Ć ć Ĉ ĉ Ċ ċ Č č Ď ď Đ đ Ē ē Ĕ ĕ Ė ė Ę
ę Ě ě Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ Ĥ ĥ Ħ ħ Ĩ ĩ Ī ī Ĭ ĭ Į į İ ı IJ ij Ĵ ĵ Ķ ķ ĸ Ĺ ĺ Ļ ļ
Ľ ľ Ŀ ŀ Ł ł Ń ń Ņ ņ Ň ň ʼn Ŋ ŋ Ō ō Ŏ ŏ Ő ő Œ œ Ŕ ŕ Ŗ ŗ Ř ř Ś ś Ŝ ŝ Ş ş Š
š Ţ ţ Ť ť Ŧ ŧ Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ų ų Ŵ ŵ Ŷ ŷ Ÿ Ź ź Ż ż Ž ž ſ Ə ƒ Ǻ ǻ Ǽ
ǽ Ǿ ǿ Ș ș Ț ț ə ˆ ˇ ˉ ˘ ˙ ˚ ˛ ˜ ˝ ΄ ΅ Ά · Έ Ή Ί Ό Ύ Ώ ΐ Α Β Γ Δ Ε Ζ Η Θ
Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί ΰ α β γ δ ε ζ η θ ι κ λ μ ν
ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ Ѐ Ё Ђ Ѓ Є Ѕ І Ї Ј Љ Њ Ћ Ќ Ѝ Ў Џ А Б В
Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Ъ Ы Ь Э Ю Я а б в г д е ж
з и й к л м н о п р с т у ф х ц ч ш щ ъ ы ь э ю я ѐ ё ђ ѓ є ѕ і ї ј љ њ
ћ ќ ѝ ў џ Ґ ґ
Ω

Categories

Categories are sorted differently from other lists. The exact order depends on the configuration of the wiki, via $wgCategoryCollation . The default since MediaWiki 1.17 is the Unicode code point order as above, but with all the lowercase letters turned into uppercase letters. More complex orderings are possible.

Sorting rows of a table

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, add the "sortable" class to the table declaration and make sure you defined headers using exclamations marks:

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

Which produces the following output:

Fruit Price
Apples £0.95
Oranges £0.85
Pears £1.15
Purple mangosteen £1.05

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.

Known issues

  • at the moment it's not possible to set an initial sort preference. See phabricator:T33332 for details.

Specifying a sort key

Depending on the wiki, data-sort-value can be used to specify a sort key.

Example:

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

gives:

Name and Surname Height
John George-Jackson Smith 1.85
Ian Ray 1.89
Zachary Bianchi 1.72
Adele Bianchi Maria 1.82
Average: 1.82

Sorting in categories

Pages in categories are sorted by their title. This can be overridden by a sort key, see Help:Categories#Sort key.

See also