Template:Number table sorting/doc: Difference between revisions

Content deleted Content added
Sort key: new section explaining the sort key
+cat
 
(33 intermediate revisions by 25 users not shown)
Line 1:
{{Documentation subpage}}
{{High-use}}
{{Template shortcut|Nts}}
{{Lua|Module:Number table sorting}}
 
{{mbox
This template can be useful when building a [[Help:Sorting|sortable table]] in which a column contains both numbers and text. This template should be applied to every number in the column.
| type = notice
| text = Note. Adding <code>data-sort-type="number"</code> to the relevant column header solves many numerical sorting problems. See {{slink|Help:Sortable tables#Forcing a column to have a particular data type}}.
}}
This template can be useful when building a [[Help:SortingSortable tables|sortable table]] in which a column contains both numbers and text. This template should be applied to every number in the column and should not be used outside of sortable tables.
 
Currently, the template works for numbers between −10<sup>308</sup> and 10<sup>308</sup>. Numbers outside this range will sort above or below other numbers depending on sign. See the [[#Limitations|Limitations]] section below.
 
By default the output is displayed using thousands separators. To display numbers as entered, use {{para|format|no}}.
 
The template generates a hidden "sort key" in the [[HTML]] markup which forces the [[JavascriptJavaScript]] [[sorting algorithm]] to sort the column alphabeticallynumerically.
 
===Purpose===
Line 14 ⟶ 19:
# When numbers are followed by some text
# When numbers are preceded by some text other than a currency symbol.
Note that some text that follows numbers is no longer a problem, and the column will still sort numerically. The percent symbol (%) for example. Or references. And that is without adding <code>data-sort-type=number</code> to the header. See: [[Help:Sortable tables#Numerical sorting problems]] for much more info.
 
==Parameters==
Line 21 ⟶ 27:
* <code>prefix</code>: To display some text before the number, use {{para|prefix|''some prefix''}}
*: <code><nowiki>{{nts|123456789.00123|prefix=approx.&amp;nbsp;}}</nowiki></code> → {{nts|123456789.00123|prefix=approx.&nbsp;}}
* <code>format</code>: For unformatted outpuoutput, use {{para|format|no}}
*: <code><nowiki>{{nts|123456789.00123}}</nowiki></code> → {{nts|123456789.00123}}
*: <code><nowiki>{{nts|123456789.00123|format=no}}</nowiki></code> → {{nts|123456789.00123|format=no}}
Line 28 ⟶ 34:
*: <code><nowiki>{{nts|-123456789.00123|debug=yes}}</nowiki></code> → {{nts|-123456789.00123|debug=yes}}
 
Apart from the added thousands separators, the numbers are formatted as supplied (scientific notation or not, leading and trailing zeros, and a zero before the decimal point or not). This formatting does not affect the sorted order except for numbers not satisfying the limitations mentioned below.
 
{{TemplateDataHeader}}
<templatedata>
{
"description": "",
"params": {
"1": {
"label": "Number",
"type": "number",
"required": true,
"description": "Your number"
},
"format": {
"label": "Format output?",
"type": "string",
"required": false,
"description": "If you do not wish the output to be formatted (i.e. separated by thousand separators), please put \"no\" in this field. (Without quotation marks.)"
},
"debug": {
"label": "Debug",
"type": "string",
"required": false,
"description": "If set to \"yes\", forces output to include debug data"
},
"prefix": {
"label": "Prefix",
"type": "string",
"required": false,
"description": "The prefix to be displayed before the number. E.g. \"Approx.\" or \"$\""
}
}
}
</templatedata>
 
==Sort key==
Line 68 ⟶ 107:
|-
| <code><nowiki>{{nts|between 2 and 3|debug=yes}}</nowiki></code> || {{nts|between 2 and 3|debug=yes}}
|-
| <code><nowiki>{{nts|between 2 and 3|debug=no}}</nowiki></code> || {{nts|between 2 and 3|debug=no}}
|-
| <code><nowiki>{{nts|10|prefix=approx.{{sp}}|debug=yes}}</nowiki></code> || {{nts|10|prefix=approx.{{sp}}|debug=yes}}
Line 145 ⟶ 186:
 
==See also==
* {{tl|NtcConvert}} - creates—has a center aligned sortable numeric table celloption
* {{tl|Dts}}Date - fortable sorting dates}}
* {{tl|Ntl}} - creates a left aligned sortable numeric table cell
* {{tl|Hidden sort key}}
* {{tl|Ntr}} - creates a right aligned sortable numeric table cell
* {{tl|Ntsh}}Number -table samesorting hidden}}—same as this template, but does not display (hides) the number
* {{tl|SmsSort}}
* {{tl|Ntsc}} - for converted units, sorts by the first number
* {{tl|val}}—displays numbers and quantities with various formatting options
* {{tl|Ntss}} - same as Nts, but allows for the number to be scaled
* {{tl|Convert}} - has a sortable option
* {{tl|Dts}} - for sorting dates
* {{tl|Sms}}
 
<includeonly>{{sandbox other||
[[Category:Sorting templates|NtsNumber table sorting]]
[[Category:Table templates]]
[[de:Vorlage:Nts]]
}}</includeonly>
[[fi:Malline:Nts]]
[[it:Template:Nts]]
[[ja:Template:Nts]]
[[mhr:Кышкар:Nts]]
[[mk:Шаблон:Пб]]
[[mr:साचा:Nts]]
[[pl:Szablon:L]]
[[pt:Predefinição:Nts]]
[[ru:Шаблон:Nts]]
[[simple:Template:Nts]]
[[sv:Mall:Nts]]
[[sw:Kigezo:Nts]]
[[te:మూస:Nts]]
</includeonly>