Help:Sorting

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by Patrick (talk | contribs) at 08:31, 30 November 2006 (moved from Help:Table). It may differ significantly from the current version.
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Tables can now be made sortable via JavaScript. Any table with class="sortable" has 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.

The sorting modes are:

  • string (ASCII) - partial list showing the order: !"#$%&'()*+,-./09:;<=>?@AZ[\]^_'az{|}~
    • for numbers the most relevant are: +,-.0123456789Ee
  • numeric (just digits, or digits and a decimal point)
  • currency
  • date (DD-MM-YYYY or DD-MM-YY), see below

The sorting mode is determined by the table element that is currently in the first row below the header (thus it may change after sorting, which can give a cycle of four or even more instead of two).

A table element consisting of just digits, or digits and a decimal point, is considered numeric. A negative number and a number in scientific notation are not recognized as number in determining the sorting mode, but if numeric sorting is used, these numbers are properly numerically sorted. Numbers with spaces or commas are treated as strings. If all numbers in a column are non-negative, alphabetic sorting can be made to correspond with numeric sorting by leading zeros, or "&nbsp;" codes which render as blank spaces, typically giving a visually more attractive result.

Links and other wiki-markup do not seem possible in headers.

See also [1].

Dates

For dates the sorting mode is based on the rendered date format. Unfortunately none of the standard formats for the date formatting feature matches either of the formats giving sorting mode "date". Thus if dates are entered in one of these standard formats the sorting mode is "string"; only for format YYYY-MM-DD string sorting corresponds to chronological sorting.

Thus the cases where we get chronological sorting include:

  • the wikitext uses any standard format for the date formatting feature, and the date format set in the preferences is [[YYYY-MM-DD]]
  • the wikitext uses format [[YYYY-MM-DD]], and the date format in the preferences is not set (this includes anon users) or set to "no preference", or set to [[YYYY-MM-DD]]
  • format DD-MM-[[YYYY]] (not recommended, except on wikis which abandon the date formatting feature in favor of this format)

Thus, users setting the preference [[YYYY-MM-DD]] and using as editor the wikitext format [[YYYY-MM-DD]] make all tables using the standard formats for the date formatting feature sortable for themselves, while making their tables sortable both for people with "no preference" and people with preference [[YYYY-MM-DD]].

If a table column contains also, or only, incomplete dates of the form [[YYYY]]-MM, this does not give complications: such an incomplete date is positioned alphabetically between the first day of the month concerned and the previous day.

If a table column contains only incomplete dates of the form [[YYYY]], this does not give complications either.

If a table column contains also, but not only, incomplete dates of the form YYYY, we have to distinguish two cases:

  • if at some point (i.e., after possible previous sorting) the form [[YYYY-MM-DD]] or [[YYYY]]-MM is at the top, sorting works fine: alphabetically, with [[YYYY]] positioned between the first day of the year concerned and the previous day.
  • if at some point the form [[YYYY]] is at the top, sorting is numerical; in this case there is no proper sorting within each year .

Sorting examples

Province Population Area (km²) Density GDP(PPS in mil. € 2003) GDP per cap. (in € 2003)
South Holland  3,453,000  2,860 1,207.3  95,868 27,825
a  2,583,900  2,660   971.4  65,295 27,169
Utrecht  1,159,200  1,356   854.9  38,355 33,148
Limburg  1,143,000  2,167   527.5  28,038 24,585
North Brabant  2,406,900  4,938   487.4  65,295 27,169
Gelderland  1,967,600  4,995   393.9  45,043 22,942
Netherlands 16,254,800 41,525   391.4 440,167 27,132
Overijssel  1,105,800  3,337   331.4  25,854 23,441
Flevoland   356,400  1,426   249.9   6,915 19,439
Groningen   575,900  2,344   245.7  18,496 32,245
Zeeland   378,300  1,792   211.1   9,354 24,706
Friesland   642,500  3,361   191.2  13,989 21,830
Drenthe   482,300  2,652   181.9  10,323 21,427

Other examples:

See also

Links to other help pages

Help contents
Meta · Wikinews · Wikipedia · Wikiquote · Wiktionary · Commons: · Wikidata · MediaWiki · Wikibooks · Wikisource · MediaWiki: Manual · Google
Versions of this help page (for other languages see further)
What links here on Meta or from Meta · Wikipedia · MediaWiki
Reading
Go · Search · Namespace · Page name · Section · Backlinks · Redirect · Category · Image page · Special pages · Printable version
Tracking changes
Recent changes (enhanced) | Related changes · Watching pages · Diff · Page history · Edit summary · User contributions · Minor edit · Patrolled edit
Logging in and preferences
Logging in · Preferences
Editing
Starting a new page · Advanced editing · Editing FAQ · Export · Import · Shortcuts · Edit conflict · Page size
Referencing
Links · URL · Interwiki linking · Footnotes
Style and formatting
Wikitext examples · CSS · Reference card · HTML in wikitext · Formula · Lists · Table · Sorting · Colors · Images and file uploads
Fixing mistakes
Show preview · Reverting edits
Advanced functioning
Expansion · Template · Advanced templates · Parser function · Parameter default · Magic words · System message · Substitution · Array · Calculation · Transclusion
Others
Special characters · Renaming (moving) a page · Preparing a page for translation · Talk page · Signatures · Sandbox · Legal issues for editors
Other languages: