Help:Sorting


 * For help sorting articles in categories, see Sort parameters in Help:Category.

Sortable tables have the ability to sort table rows based on the values inside a specific column. This is done through.

Creating a sortable table
Making a table sortable is easy since all that is required is appending the "sortable" class. However, certain situations – such as sorting with numbers or using a table footer – may require extra input, as detailed further down the page.

For example:

This results in:

Clicking the arrows will let you sort the column numerically then alphabetically. If you want to sort by multiple columns, hold down the Shift key when you click your second column.

Advanced sorting
By default, the system guesses the type of data in each column by looking at the first five rows. This works most of the time but can be confused by inconsistent data or unexpected characters. For example, 10cm, 20cm, 100cm will be sorted as 10cm, 100cm, 20cm (sorted by "letters" rather than numerically). This can be fixed by using the "data-sort-type" attribute on column headers, or by using the "data-sort-value" attribute on individual cells.

data-sort-type
can be added to a column header to specify the column's data type. Several types are supported, but the most common ones are:
 * text - Sorts text by symbols, digits, and letters in that order.
 * number - Expects a numerical value, points, commas, spaces, "+", or "-" (ex: +1,234.5). Other characters after the number will be ignored.
 * currency - Expects a number with $, £, €, or ¥ in front (ex: $1.00, ¥10,000)
 * date - Expects a compatible date format (ex: 25-12-2001, 25 Dec 2001)

Note that if a cell's contents do not match the column's specified type, it may be treated as having a value of zero.

For example:

This results in:

data-sort-value
Sometimes what you want to show in a column doesn't correspond to what order you would like it sorted by. In cases such as these  is used.

Example 1:

This results in:

Example 2:

This results in:

Date sorting
This results in:

Unsortable columns
If you have a table where you want one of the columns to not be sortable, you can do this by adding the class "unsortable" to its header.

Example:

This results in:

Table footer
If you don't wish for a row at the bottom of a table to be sorted (such as a "totals" row), this can be accomplished by adding  to the row.

Example:

This results in:

Further help and feedback
de:Hilfe:Sortierbare Tabellen es:Ayuda:Tablas ordenables fr:Aide:Tri it:Aiuto:Ordinare ja:ヘルプ:ソーティング pl:Pomoc:Sortowanie ru:Справка:Таблицы/сортировка tr:Yardım:Sıralama uk:Довідка:Таблиці/сортування zh:Help:表格排序