Tɛmplet:Number table sorting/doc

Diyila Dagbani Wikipedia

This template can be useful when building a 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 −10308 and 10308. Numbers outside this range will sort above or below other numbers depending on sign. See the Limitations section below.

By default the output is displayed using thousands separators. To display numbers as entered, use |format=no.

The template generates a hidden "sort key" in the HTML markup which forces the JavaScript sorting algorithm to sort the column alphabetically.

Purpose[mali mi di yibu sheena n-niŋ]

There are at two cases where this template is useful:

  1. When numbers are followed by some text
  2. When numbers are preceded by some text other than a currency symbol.

Parameters[mali mi di yibu sheena n-niŋ]

The template has only one required parameter: a real number. These examples use the name of the redirect, {{nts}}, for brevity.

Optional parameters
  • prefix: To display some text before the number, use |prefix=some prefix
    {{nts|123456789.00123|prefix=approx. }}
  • format: For unformatted output, use |format=no
    {{nts|123456789.00123}}
    {{nts|123456789.00123|format=no}}
  • debug: To display the sort key, use |debug=yes.
    {{nts|123456789.00123|debug=yes}}
    {{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.

What is template data?[mali mi di yibu sheena n-niŋ]

Template data is the standardized description of a template, used by the default VisualEditor, the optional 2017 wikitext editor and other tools to improve the template-editing experience for the user. Both VisualEditor and the 2017 wikitext editor include a wizard to edit templates, but for the wizard to be most useful, it needs to present specific information to the user about each template, such as a short description of the template's purpose and its parameters. This information is codified formally (by any wiki editor) using template data.

Editing without template data[mali mi di yibu sheena n-niŋ]

Without template data, each parameter needs to be added manually when inserting a new template.

No information is provided about what the value of the parameter should be.

Editing with template data[mali mi di yibu sheena n-niŋ]

With template data, a list of supported parameters (and their description) is provided for the template.

Template data provides context for each parameter, and makes it much easier for users to modify templates.

Adding template data[mali mi di yibu sheena n-niŋ]

Anyone can help by adding template data to templates (particularly high-profile ones, such as infoboxes) so that they are easier to edit in VisualEditor. The following is a minimal example, placed on a template's documentation page:

<templatedata>{
  "description": "insert description here",
  "params": {
    "first parameter": {
      "label": "x",
      "description": "x",
      "type": "string",
      "suggested": true,
      "autovalue": "derived automatic value",
      "default": "default value",
      "required": false
    }
  }
}</templatedata>

You can also add or edit template data using a GUI, by pressing the following button which appears at the top of the edit page: Edit template data

The template data tutorial explains in detail how to add template data information to a template.

Adding suggested values for parameters[mali mi di yibu sheena n-niŋ]

The parameter property suggestedvalues lets you define a list of parameter values to be shown to VisualEditor users in a dropdown for easy selection. This can be done either directly in JSON or using the TemplateData editor with no coding required. Both methods are explained in detail below.

Once the values have been added to template data, the VisualEditor will display them in a combo box (a dropdown into which users can also enter a custom value). The user selects the desired value by clicking on it. If the list of values is long - for example, a list of a country’s states - the user can begin typing in the field, whereupon the list will be filtered to show only values containing the typed text. To change an entered value, the user must simply clear the field, and the full dropdown list will appear again. If the user needs a value not included in the list (for example, "message in a bottle") they can type it in manually.

For suggested values to be displayed in the VisualEditor, the parameter’s type must be set to one of the following options:

  • content
  • line
  • string
  • number
  • unknown
  • unbalanced wikitext.

Other types (file, page, template, user, date, boolean, URL) are not currently supported because they have special functionalities in the VisualEditor already (such as autocomplete) which would interfere with the dropdown menu for suggested values in the VisualEditor.

Adding suggested values for parameters in wikitext[mali mi di yibu sheena n-niŋ]

To add suggested values to any parameter type, add the new property “suggestedvalues” to the parameter in JSON. The “suggestedvalues” attribute must be a list of strings.

An example might look like this:

"media_type": {
	"label": "Type of media",
	"example": "Newspaper",
	"type": "string",
	"description": "In what medium was the article published?",
	"suggestedvalues": [
    	"Journal",
    	"Book",
    	"Newspaper",
    	"Magazine"
	]
}

Adding suggested values for parameters with the template data editor[mali mi di yibu sheena n-niŋ]

For the parameter types listed above, you can add suggested values using the template data editor.

Step 1. Click on "Manage TemplateData".
Step 2. Click on the name of the parameter you want to add suggested values to.
Step 3. If it’s not already, set the type of the parameter to one of the following: content, line, string, number, unknown or unbalanced wikitext. A new input field "Suggested values" will appear. If the parameter is already set to one of these types, the input field should already be visible.
Step 4. Type in the suggested value(s), including any spaces and special characters, and press enter to add it to the list.

Here you can see an example of how to add suggested values in the TemplateData editor.

Used templates[mali mi di yibu sheena n-niŋ]

See also[mali mi di yibu sheena n-niŋ]

Template parameters

ParameterDescriptionTypeStatus
Number1

Your number

Numberrequired
Format output?format

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.)

Stringoptional
Debugdebug

If set to "yes", forces output to include debug data

Stringoptional
Prefixprefix

The prefix to be displayed before the number. E.g. "Approx." or "$"

Stringoptional

Sort key[mali mi di yibu sheena n-niŋ]

The sort key is a nineteen-digit number. For numbers within range the first four digits are determined by the number's sign and order of magnitude and the next fifteen digits are determined by the number's sign and significand.

Numbers within range
  • For numbers between 10−308 and 10308 the first four digits are calculated by adding 7000 to the order of magnitude and the next fifteen digits are calculated by multiplying the significand by 1014.
  • For numbers between −10−308 and −10308 the first four digits are calculated by subtracting the order of magnitude from 2999 and the next fifteen digits are calculated by subtracting the significand from 10 multiplying the difference by 1014.
  • The sort key for 0 is 5000000000000000000.
Numbers out of range
  • Numbers larger than 10308 are assigned the sort key 9000000000000000000.
  • Numbers smaller than −10308 are assigned the sort key 1000000000000000000.
  • Numbers between 10−308 and 0 or between 0 and −10−308 are assigned the sort key 5000000000000000000.

Limitations[mali mi di yibu sheena n-niŋ]

  • Any subset of numbers larger than 10308 are sorted together.
  • Any subset of numbers smaller than −10308 are sorted together.
  • Any subset of numbers between 10−308 and −10−308 are sorted together.
  • If a non-numeric value is given as the first unnamed parameter the results are undefined.
  • The hyphen minus sign is converted into a true minus sign; note, though, that this means no more than 12 significant figures are possible.
  • A prefix (using the prefix parameter) does not affect the sort order.

Examples[mali mi di yibu sheena n-niŋ]

{{nts|123456789.00123}}

For text which follows a number, {{nts|123,456}} as of 2012 displays 123,456 as of 2012 with a numerical sort key of 123456. This forces numerical sorting in the cell using this value instead of the default alphabetical sorting.

Below are more examples, some of which illustrate the limitations listed above.

markup sortkey and number error spillover
{{nts|debug=yes}}
{{nts||debug=yes}}
{{nts|between 2 and 3|debug=yes}}
{{nts|between 2 and 3|debug=no}}
{{nts|10|prefix=approx.{{sp}}|debug=yes}}
{{nts|-5|debug=yes}}
{{nts|-4|debug=yes}}
{{nts|-73|debug=yes}}
{{nts|-67|debug=yes}}
{{nts|-20345678901234567.12345678|debug=yes}}
{{nts|123.456e3|debug=yes}}
{{nts|123.456e2|debug=yes}}
{{nts|20345678901234567.12345678|debug=yes}}
{{nts|100345678901234567.12345678|debug=yes}}
{{nts|1234567890123456.12345678|debug=yes}}
{{nts|234567890123456.12345678|debug=yes}}
{{nts|34567890123456.12345678|debug=yes}}
{{nts|4567890123456.12345678|debug=yes}}
{{nts|567890123456.12345678|debug=yes}}
{{nts|67890123456.12345678|debug=yes}}
{{nts|7890123456.12345678|debug=yes}}
{{nts|890123456.12345678|debug=yes}}
{{nts|90123456.12345678|debug=yes}}
{{nts|0123456.12345678|debug=yes}}
{{nts|123456.12345678|debug=yes}}
{{nts|23456.12345678|debug=yes}}
{{nts|3456.12345678|debug=yes}}
{{nts|456.12345678|debug=yes}}
{{nts|56.12345678|debug=yes}}
{{nts|6.12345678|debug=yes}}
{{nts|.12345678|debug=yes}}
{{nts|0.12345678|debug=yes}}
{{nts|0.02345678|debug=yes}}
{{nts|0.00345678|debug=yes}}
{{nts|0.00045678|debug=yes}}
{{nts|0.00005678|debug=yes}}
{{nts|0.00000678|debug=yes}}
{{nts|0.00000078|debug=yes}}
{{nts|0.00000008|debug=yes}}
{{nts|.00000008|debug=yes}}
{{nts|0|debug=yes}}

See also[mali mi di yibu sheena n-niŋ]