Help:Sorting

From semantic-mediawiki.org
Jump to: navigation, search

Contents

General

Sorting is alphabetic for pagenames, and for attributes of type string. It is numeric for attributes of type integer and float, taking into account units. It is chronological for attributes of type date.

Sort parameter

The sort parameter specifies a relation or attribute that determines the order of the selected pages. Sorting based on a relation or attribute requires that the selection is restricted to pages for which that relation or attribute is defined.

The sortkey is one of the instances of the object or value (there is at least one because of the just mentioned condition; if there are more it seems arbitrary which one is used as sortkey, perhaps just the first in the database). The default sortkey is the name, without namespace prefix, of the selected page. This applies even in the case of enumeration of pages in the query.

The object or value used as sortkey needs not be among the displayed items.

The order parameter can be "ascending" (equal to "asc", default) or "descending" (equal to "desc" or "reverse"). It applies both to the order of the selected pages (in a table: rows) and to the instances of an item to be displayed for a page (in a table: multiple elements in a cell).

The order of the items to be displayed (in a table: columns) is as specified.

Examples (the last one shows that the sort parameter is ignored if the attribute concerned is not used for selection):

<ask>less than::+*</ask>


order=desc: <ask order=desc>less than::+*</ask>


sort="less than": <ask sort="less than">less than::+*</ask>


sort="less than" order=desc: <ask sort="less than" order=desc>less than::+*</ask>

<ask sort="Population">[[Population:=+]][[Population:=*]]</ask>
<ask sort="Population">[[Population:=+]]</ask>
<ask sort="Population" order=desc> [[Category:Cities]] [[Population:=+]] [[Population:=*]]</ask>
<ask sort="Population"> [[Category:Cities]] [[Population:=*]]</ask>

give:

<ask sort="Population">+warning.png"+" is not a number.*warning.png"*" is not a number.</ask> <ask sort="Population">+warning.png"+" is not a number.</ask> <ask sort="Population" order=desc> [[Category:Cities]] +warning.png"+" is not a number. *warning.png"*" is not a number.</ask> <ask sort="Population"> [[Category:Cities]] *warning.png"*" is not a number.</ask>

Data not available for all pages

Sorting based on a relation or attribute requires that the selection is restricted to pages for which that relation or attribute is defined: if some pages of the desired selection do not have the required annotation, the others cannot be sorted. To have all pages, with those sorted which can be sorted, requires a query giving those sorted that can be sorted, and a second query for the rest; a difficulty in avoiding duplication is that there is no selection criterion "relation/attribute A is undefined". Two possible workarounds are:

Javascript sorting

Tables created by Semantic MediaWiki are connected by the delivered stylesheet to a Javascript program that allows the user to sort, inside the browser, the rows of the displayed table by the content of a specified column, either ascending or descending. This overrides the order of the rows as specified in the query, but leaves intact the order of multiple items in a cell (ascending or descending, as specified by the sort parameter).

First population table on this page:

Numeric values without grouping character are numerically sorted. However, "12,345" is sorted based on "12", so for ascending order it comes before 13.

Second and third population table on this page:

Sorting is alphabetical, with the comma before the digits, for ascending order 1,795,000 comes before 143,346.

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox