Help talk:Sortable tables/Archive 3

List of Indian national cricket captains
Can anything be done for a table like this, which spans both multiple rows and columns? I've racked my brains but could not figure anything out. This is part of a much longer table. Thanks, Abeer.ag (talk) 18:56, 21 July 2009 (UTC)


 * According to our current conversation on irc://irc.freenode.net/mediawiki, it seems to be currently impossible to do that. You can either split your data in a few sortable lines, or develop a PHP extension to sort them in block. JackPotte (talk) 00:12, 15 October 2009 (UTC)
 * I know it's not the "right" way, but my suggestion is to do it like:


 * Well, it's not perfect, but you see what I'm trying to do ~ 10nitro (talk) 16:43, 1 November 2009 (UTC)

Help with design of a table
Some of the entries in the table at List_of_National_Treasures_of_Japan_(castles) are too long ("construction"), that's why I would like to split it in shorter entries. How shall I do that? The first column ("name") should not be changed as it contains the official name of the structure. Preferrably I would like to have a rowspan in the first column and extra rows for the various sub-structures ("Tenshu", "Northwest Small Tower",...). The problem with this is that I would lose the sorting feature as far as I know. Is there a workaround to have rowspan and sorting or a better way to arrange the table? bamse (talk) 10:43, 3 November 2009 (UTC)

Help with Alternating Colours Feature
I would like to be able to use the alternating colours feature of this without making the tables sortable. I.e. ideally I'd like to extract the alternate colours code from the rest of the sortables code and assign it to tables via a seperate class.

Example: {|class="prettytable alternate"

Unfortunately, I am a JS novice and, even after playing around with some of the code for several days, I can't seem to get it to work. Can anyone help? —Preceding unsigned comment added by 94.195.252.155 (talk) 20:24, 13 December 2009 (UTC)

Conditional formating based on sort parameter?
I am interested in having some text in column 1 be bold depending on which of the columns are sorted.

ie: if column 2 is sorted:

ie: and if column 3 is sorted:

I am hoping someone has something that sounds like "if(sort=2) then(valuables) else(valuables)" Jrkenti (talk) 16:25, 17 December 2009 (UTC)

Sorting of numbers does not work
I am preparing a table with sortable columns here. However the "Area" column does not sort as expected by number, but by digit. How can I fix this? Do I need to add hidden sortkeys or is there a more convenient way to achieve this?bamse (talk) 10:41, 9 January 2010 (UTC)


 * After several attempts, I determined it is not any one thing. At first I thought it might be the non-breaking space that convert outputs, for example, , but a jerry rigged test proved that wasn't the cause.  Then I thought it might be the units  so I removed those, but no luck.  Then it seemed like maybe the decimal point was the issue, so I removed all those—and sure enough it sorted correctly.  But then adding back the units broke it again.  It seems like if the column doesn't contain pure integers, sorting considers them character entities.


 * With that, the most portable solution is to use the solution.  I saved a working test to your page.  —EncMstr (talk) 17:37, 9 January 2010 (UTC)


 * Thanks a lot. bamse (talk) 17:57, 9 January 2010 (UTC)

Sorting split tables
Hi, Is there any way to sort "split tables"?

An example is given here. What I would like is that if the table is sorted by "rider", both tables are sorted, such that "Abraham Olano" is first, followed by "Aitor González", "Alberto Contador" ... and "Alexandre Vinokourov" (all from the right table), and then "Angelino Soler" (from the left table). I know it should not sort by first name but by last name, and I know how to solve it, I just haven't done this yet.

If it is possible, it needs some changes in User:EdgeNavidad/Template:Cycling past winner mid, the template that defines the head of the tables, and User:EdgeNavidad/Template:Cycling past winner mid, the template that defines where the tables are split. I think that currently it is impossible because they are two separate tables, but that is only the implementation, and may change. If it is possible to have it technically be one table, but visually "split", it is also good.--EdgeNavidad (talk) 09:00, 17 February 2010 (UTC)

Sort issue in Safari 4
While working on several Featured Lists, I've consistently had a reviewer who uses Safari expressing issues with a certain column's sort despite it working fine on IE8 and FF3+. I decided to download Safari and test it myself. The column in question contains years and year ranges (with en dash). It appears it is doing multiple sorts, with some sorts evaluating correctly while the others separate the years with en dashes.

Well, the example above isn't having the same result as one of the articles in question as it is not sorting ascending correctly at all. Descending seems to work. Check out this article for an example.

I'm sure I could get around this by using a template like SortKey, but I don't feel I should have to. Regardless if this column is being evaluated as a number or string, it should still sort the same. I don't understand how Safari is saying that "1936–2001" is less than "1923–1932". It should the "1" in the first columns and then the "9" in the second, and then the "2" and "3" in the third and know that "2" is lower. I just don't want to have to use a template to fix something that may be a software/MediaWiki issue.—NMajdan &bull;talk 18:23, 22 February 2010 (UTC)
 * I am said "reviewer". I get problems with that example table in both directions using Mac OS X's Safari (v4.04) and would be interested in an answer so I can stop bugging our nominators over at FLC, most of whom seem to use IE or Firefox.  The Rambling Man (talk) 18:33, 22 February 2010 (UTC)


 * There's no fix short of using one of the sort templates. FF + IE use a string sort in most cases.  Safari initially uses a numeric sort, except when it encounters the number ranges, it's obviously not a number so it does something not so good.  Without convincing Safari's developers to reproduce FF behavior—and then getting all users to immediately upgrade—the only solution is to use a sort key.  —EncMstr (talk) 18:44, 22 February 2010 (UTC)


 * Looked into it: On the first sort, the first tablecell has a number. The script finds the number, and sorts everything with the number sorter. The numbersorter supports +-, and . besides the actual numbers. A range is NOT a number. The tablecells that were not recognized by the number sorter, get a sortkey of 0. Thus all ranges get listed at the top. Now when you reverse, the first element is a string. That makes all elements be treated as strings, and results in proper sorting (in this specific case, it would break on negative numbers or currency of course). I'm not sure why FF has no problem. —Th e DJ (talk • contribs) 20:16, 22 February 2010 (UTC)
 * The difference is caused due to a problem with the 'parseFloat' function of Safari. It is webkit bug 31349. It doesn't recognize non ascii characters, and instead of 'cutting off' the parsing, returns NaN, what it shouldn't do... —Th e DJ (talk • contribs) 20:47, 22 February 2010 (UTC)


 * Well, bummer. If its a browser bug, than I'll workaround with templates. Thanks for the help.—NMajdan &bull;talk 20:58, 22 February 2010 (UTC)

displaying e.g. James Harris (politician) as James Harris in sortable list?
How does one make e.g. James Harris (politician) display only as James Harris while still linking to the correct one? How does one still it sortable on lastname "Harris" only, ignoring "(politician)"? Шизомби (Sz) (talk) 04:21, 31 March 2010 (UTC)

Col span and sortable issue
Hi in looking at the work here, i was wondering how i could either make it so the "no reward" column can either:
 * Be sortable as a "Z" value for all three columns in the middle while maintaining its column span. or
 * Be sorted to the bottom but allowing it to still move in response to the year sorting column.

Thanks, Salavat (talk) 12:51, 4 April 2010 (UTC)

Sorting present as a year
During the FLC of List of members of the Norwegian Nobel Committee (see Featured list candidates/List of members of the Norwegian Nobel Committee/archive1) a problem has arisen while trying to sort a column of years (the 'end' column), where five are listed as 'present' and sorted as. It seems to sort correctly in Firefox, Opera and IE, but not in Safari. Since this is what is holding back the FL status, perhaps someone with more expertise could take a look? Thanks, Arsenikk (talk) 11:17, 5 April 2010 (UTC)
 * What's the difference between sort and sortkey? I've also received some criticism for the lack of Safari sort-support from the same person as you. Using sortkey resolved the issues I had. I have Safari for Windows on my work PC, so when I get to work in a few hours, I'll take a look.—NMajdan •talk 12:14, 5 April 2010 (UTC)
 * Yes, I do check that a table sorts correctly in my (commonplace Mac OS) browser, and it's never a "criticism" more of an observation that sometimes, the assumed sorting in Internet Explorer etc doesn't necessarily read across to all other browsers. I hope we can find a suitable solution which pleases all parties.  The Rambling Man (talk) 16:05, 5 April 2010 (UTC)
 * Try adding the sort template to all values in the End column. I tried this here and it appears to be working in Safari on Windows.—NMajdan •talk 16:20, 5 April 2010 (UTC)

Sort a table with two rows of title
Hi i'm a french user and on fr i want to sort the following table from the second row of title. Is it really impossible or I missed something?

--kirikou_fr (talk) 13:00, 6 April 2010 (UTC)
 * Check out List of Philadelphia Flyers players, I think its doing what you are wanting to do.—NMajdan •talk 15:17, 6 April 2010 (UTC)
 * Mark the top rows with class="unsortable", and the bottom rows with class="sortbottom". This works. verdy_p (talk) 13:25, 3 July 2010 (UTC)
 * Note that when there are merged cells (cells using colspan>1 or rowspan>1, they behave as if they were only the cell at the top-left of the merged area; in your example you can"t sort all columns because the sort icons options are placed only on the first row, where some header cells are merged in your example. You should be able to put the sort icon on the header cells of the second row, but I don't think it's possible for now with the current Javascript. so use the second row of header to display additional grouped headers
 * The effect of merged cells within the sortable rows is also currently unpredictable:
 * I don't think that the javascript is able to count cells correctly for determining their effective column number when some of them are using colspan, and there's currently no support for column groups (&lt;colgroup&gt; in HTML).
 * The effect of merged cells with rowspan>1 is also unpredictable as there's also still no support for row groups (&lt;thead&gt;, &lt;tbody&gt;, &lt;tfoot&gt; in HTML).
 * WikiMedia should be updated, even if tables are used without the sortable option, to support the standard column groups and row groups of HTML, which are needed for accessibility as well as to simplify the style formatting. Wikimedia just supports the 3-layers model of tables in HTML3, and does not support the 6-layers model of tables in HTML4 and higher.
 * The trick of using class="unsortable" for top rows, class="sortbottom" for bottom rows is still a trick and not accessible. It should be replaced by actual support of standard row groups (&lt;thead&gt; and &lt;tfoot&gt; respectively).
 * And then, sorting should be able to avoid breaking &lt;tbody&gt; row groups everytime the header cells are in a &lt;thead&gt; row group; and it should stop sorting &lt;tbody&gt; row groups below the thead row group containing the clicked "sort icon", as soon as it detects a non-&lt;tbody&gt; row group.
 * verdy_p (talk) 13:37, 3 July 2010 (UTC)

Enhancement request
Numeric sort should recognise a proper minus sign (or en dash) as designating a negative number, not just a hyphen. —Preceding unsigned comment added by 86.138.42.179 (talk) 03:48, 7 April 2010 (UTC)


 * Numeric sort where ? —Th e DJ (talk • contribs) 15:13, 17 April 2010 (UTC)
 * Numeric sort applies automatically, when the Javascript detects that columns contain numeric data (it just parses the text in the first cell of the sorted column to see if it looks like valid numeric data).
 * Unfortunately, it just assumes the US format for numbers, with commas just meaning a digit group separator (ignored for the purpose of sorting numeric values), and dot meaning a decimal separator. In French this is exactly the opposite (however using a dot for grouping digits is not recommanded, French prefer spaces, preferably unbreakable thin spaces, named "fine" in French typography, i.e. &amp;nnbsp; = NARROW NON BREAKING SPACE in Unicode). verdy_p (talk) 14:02, 3 July 2010 (UTC)
 * The javascript should be able to detect that this is istill numeric data, but when computing values, it should correctly make the distinction between US format "1,234,567.89" and French format "1 234 567,89" (for the same numeric value) : the US format should be assumed only if commas and dots are used simultaneously.
 * But then you'll have the ambiguity of "123,456" which means 123456 in English, but 123456 in French.
 * "123.456" is not ambiguous (it is using US format only with a decimal separator), and "123 456" is also not ambiguous (the prefered international format interpreted correctly but in US and elsewhere, with group separator as whitespace) verdy_p (talk) 14:11, 3 July 2010 (UTC)

I wonder why we would bother to scan the first entry for digits etc. Why not just pass it to parseFloat and see if it parses? I suspect that might also solve the internationalization problems. --Doradus (talk) 15:15, 19 December 2010 (UTC)

Sorting empty cells always last/first - is this possible?
While fixing the sorting for the valuation column in List of acquisitions by Oracle table, I realized that the "N/A" values should actually be treated like an empty cell. For sorting reasons however they are treated like $0 now. Is there a way to keep them always appearing after the rows with filled currency values, like a Order by with NULLS LAST in SQL? The handling of empty cells should also be better explained in the help page here. I was also wondering what sort mode is actually used if the first row cell of a sort column happens to be an empty cell? How can you enforce a specific sort mode for empty cells? --Berny68 (talk) 10:14, 17 April 2010 (UTC)
 * These are all known issues of the sortable tables system. Bugzilla is full of them. —Th e DJ (talk • contribs) 15:16, 17 April 2010 (UTC)


 * The sort mode is based on the first non-blank element.--Patrick (talk) 15:43, 17 April 2010 (UTC)


 * Careful use of the template can achieve the desired effect:
 * {| class="wikitable sortable"

! Amount !! Desc
 * $18 billion || Administrative
 * $30 billion || Marketing
 * N/A || Education
 * $19 billion || R&D
 * }
 * —EncMstr (talk) 17:35, 17 April 2010 (UTC)
 * $19 billion || R&D
 * }
 * —EncMstr (talk) 17:35, 17 April 2010 (UTC)
 * —EncMstr (talk) 17:35, 17 April 2010 (UTC)


 * Thank you for all the answers. The example doesn't show the desired effect though. N/A is shown last when Amount is sorted in ascending order, in descending order however it's shown first. I want it show up after all non-N/A rows independent of Amount sorting.--Berny68 (talk) 18:12, 17 April 2010 (UTC)


 * Ah, I guess I didn't fully understand what you are asking. I've since thought about this for awhile but can't think of any way to achieve it.  —EncMstr (talk) 20:07, 17 April 2010 (UTC)

Alfabetic versus numerical sorting behaviour on same data-type
Hello, on List of FC Barcelona players I've encountered an odd behaiour. One column (Apperances) sorts alfabetically, while another (Goals) sorts numerically. They contain the exact same type of data, so it's a mystery to me. Help appreciated! Sandman888 (talk) 22:17, 30 April 2010 (UTC)


 * They seem to work in the same wrong way: when "N/A" is at the top they sort alphabetically. You can apply Help:Sorting, choosing whether "N/A" is positioned like a very small number or like a very large one. (It is not possible to position them at the bottom regardless of ascending or descending sort order.)--Patrick (talk) 07:54, 1 May 2010 (UTC)
 * I've added span style="display:none">0</span before N/A, before i had used the hs template. But it doesn't help. I'm using Safari on a Mac btw. Sandman888 (talk) 15:21, 1 May 2010 (UTC)
 * you could always use the template N/A, but then you would have to make sure that N/A is smaller then the actual zero values. Salavat (talk) 15:28, 1 May 2010 (UTC)
 * Pad the numbers with the invisible character & (at least one to force alphabetic sort mode).--Patrick (talk) 22:08, 1 May 2010 (UTC)

Auto-archiving
Wd anyone mind if I sat this page up for auto-archiving as it is growing painfully long? Sandman888 (talk) 22:36, 30 April 2010 (UTC)
 * I've searched and found that this page isn't in the archiving bot scope. JackPotte (talk) 16:30, 22 May 2010 (UTC)

convert and sort templates giving an alphabetical sort of numbers
I am trying to get List of protected areas of Svalbard to sort correctly. It contains a km2 and sq mi entry created with  which is mixed with emdashes, entered as. The list will then typically sort alphabetically rather than numerically as a descending sort, but correctly in an ascending sort. Can someone take a look and perhaps find out what am I doing wrong? Thanks, Arsenikk (talk) 20:05, 17 May 2010 (UTC)

Double Sortable Class
I've noticed that most tables on Wikipedia articles have "wikitable sortable sortable". I copied a table over onto my wiki and it worked fine. I then just use "wikitable sortable" instead of "wikitable sortable sortable" and it still displayed the same. What is the purpose of the double mentioning of sortable? If possible could someone let me know on my talk page. Thanks Holygamer (talk) 21:55, 5 June 2010 (UTC)


 * I think it is an error, and there is no difference.--Patrick (talk) 00:04, 6 June 2010 (UTC)

Problems with alpha-numerical sorting
After reading the article, I still do not understand how to make an alpha-numerical value be sorted in tables. For example, in the article, when the last row is sorted, it becomes "row 1, row 10, row 11, row 2, row 3". Is there a way for this one to be sorted correctly?  No News  !  23:18, 2 July 2010 (UTC)
 * No; this is too complex for the Javascript to infer the correct sort order. You have to help Javascript by providing hidden sort keys. verdy_p (talk) 14:14, 3 July 2010 (UTC)
 * How do I do so, then?  No News  !  03:49, 4 July 2010 (UTC)
 * You have to use one of these templates for each cell of the table, to force a sortingorder. —Th e DJ (talk • contribs) 14:12, 14 July 2010 (UTC)

The default sorted column in sortable table
I would like to "sort by default" for a particular column in my table by alphabetical order. Is there any shortcut to decide which column is the sorted by default. Kasaalan (talk) 12:19, 14 July 2010 (UTC)
 * The coded order is the default order. There is never any automatic sorting. —Th e DJ (talk • contribs) 14:13, 14 July 2010 (UTC)
 * Is there a reason for this? This would really help in big tables. daviddoria (talk) 15:23, 13 August 2010 (UTC)
 * agree. definitely need this — Preceding unsigned comment added by 160.79.132.254 (talk) 00:25, 20 December 2011 (UTC)
 * Any update on this feature? Would be great.Mattximus (talk) 20:43, 15 April 2012 (UTC)

Accessibility issues when implementing "rank" in a separate table
The following note was left on my talk page, along with a revert of :

I replied as follows, but decided this topic merits a broader audience.


 * yes, that was a lot of work, most of which had absolutely nothing to do with row numbering. You said that "References in the chart break the row alignment between rank column and main table."  I see your point, and accept that argument, but it's an incomplete argument. In fact, said alignment is already broken, and part of my reasoning for doing what I did was to fix the very problem of which you speak! Perhaps the real issue is the fragility of an implementation that uses a separate table to define a "rank" column. Frankly, from an accessibility perspective, I think that such separate-table implementations are a very bad idea that should be eliminated from Wikipedia.  I apologize if those are your invention, but that's the truth.


 * Please remember that not everyone is using the same device and browser that you are using. Are you aware that for every user that has their browser set with a zoom any larger than 100% (which is a very large population of users), then "rank" columns are only meaningful on very narrow tables, such as the demo tables on Help:Sorting? In real life examples with wide tables, such as List of countries by intentional homicide rate, the rank column becomes meaningless drivel the instant any row changes height due to word wrapping.  For example, zoom the page to 150%, and you will see that the final rank, 218, now aligns somewhere in the middle of the table!


 * By eliminating the needless "See notes below" column, it doesn't fix the problem entirely, but it narrows the table considerably, making the zoom less of an issue. Further, given the range of devices that may be used for display, articles are not supposed to be positionally "self-aware", using words like "shown below" or "on the right". There's a guideline about that somewhere, but I don't have the time to look for it right now. The use of  and  templates is a simple (for both editor and reader), intuitive, officially-sanctioned, and meaningful way of presenting references and notes within a table. Sprinkling some notes at the top of the table, some at the bottom of the table, and some in a superfluous column on the side is certainly not sanctioned, nor is a  separate rank column.


 * If you have any ideas to solve this issue, I'd love to hear it. I also suspect that we should elevate this conversation to a broader audience, like Help_talk:Sorting.  In fact, don't bother replying on my page, I'll just copy/paste this over there now. — groll tech   ( talk ) 18:47, 27 July 2015 (UTC)


 * What you say is true. And that is why there are some bug threads about it, one of which I started. See the thread links in the row numbering sections in Help:Sorting. Row numbering needs to become an integral part of tables via some class like class="wikitable sortable autonumber". In the meantime we are stuck with what we have.


 * On List of countries by intentional homicide rate I narrowed the notes column further. I also narrowed the years column further. So the row numbering now works at a narrower screen size than before. The table is now narrower than what you got it down to. When I am at 133% zoom the row numbering breaks down for me when I go below 1280 pixels wide. Without zoom I can go down to 1152 pixels wide.


 * One thing Wikipedia might do is to free up the right sidebar that shows up for some reason at some lower screen resolutions. I see now that using zoom causes the right sidebar to expand, and block table expansion. That might be something the MediaWiki developers might fix. I think it may have to do with complicated CSS, and sizes set in em units.


 * By the way, one part of your solution made things worse. The superscript (of the reference notes) breaks row numbering at all screen resolutions, and not just narrower ones. --Timeshifter (talk) 03:26, 28 July 2015 (UTC)


 * There are Phabricator threads asking for a table option for a fixed column, a static rank-order column, or row numbering. See T42618. It supercedes T42634. --Timeshifter (talk) 07:13, 15 August 2015 (UTC)
 * There is a working patch. I don't know what the holdup is with the patch being implemented. See T42618. --Timeshifter (talk) 12:36, 5 December 2015 (UTC)

Update on wikitable caused several problems in sortable tables.
The new display of sortable buttons in column headers of a sortable table caused several good-looking tables to be ruined. Things noticed:

(see its effects on table examples in: Help:Sorting)
 * Table headers having a separate row for sorting now have their main headers also have these buttons. In addition to looking redundant, these main header buttons also take up the space that was intended to be used by the other columns.
 * Nested tables (that are unsortable) also have these sorting buttons at their headers when they are nested inside a sortable table.
 * Even table 'footers' have these up-down sorting buttons.

It appears the solution I know of is at the moment is to painstakingly add class="unsortable" to all headers (and footers) so that these sorting buttons disappear. Is there a better/easier solution than this? Sanglahi86 (talk) 18:28, 5 February 2016 (UTC)


 * Looks like a bug that needs to be reported to Phabricator. I don't have time now. I don't know when I will get time. --Timeshifter (talk) 01:33, 8 February 2016 (UTC)

Handing refs on dates?
In List of Alpha Kappa Psi chapters there are a few dates that have references, so the entries in the table are like

January 5, 1900

January 6, 1900

January 8, 1900

Any suggestions on how to handle this? Naraht (talk) 18:37, 5 July 2016‎ (UTC)
 * try dts. Frietjes (talk) 13:12, 3 August 2016 (UTC)
 * Just on the ones with refs, or do all need to be changed?Naraht (talk) 14:42, 3 August 2016 (UTC)
 * Naraht, if you use dts you will probably need to change them all. if you just want to modify the rows with refs, you can try the method described in specifying a sort key for a cell.  unfortunately, that does require specifying the date twice.  another method would be to put the reference in its own column, but that splits the ref from the information being referenced.  you could try Forcing a column to have a particular data type, but that really only works in limited situations. Frietjes (talk) 18:13, 3 August 2016 (UTC)

Sort ascending/descending is backwards
Ascending sort means that the values get bigger as you go down, descending sort means the values get smaller as you go down. Currently this is reversed. . — Preceding unsigned comment added by 143.48.49.193 (talk • contribs) 11:32, 4 March 2016‎
 * You link to Sorting. I think you are referring to the tooltip on the sort button? If so, I see that the tooltip label changes depending on whether clicking it will sort the column in ascending order or descending order. So if the column is currently in ascending order, then the tooltip says "Sort descending". --Timeshifter (talk) 19:04, 4 March 2016 (UTC)


 * It wasn't just there. I just corrected Help:Sorting on Wikimedia, referring the edit summary to this that I wrote on the Talk page :


 * Order in the court!
 * Please note the definitions of ascending and descending order:
 * The order in how information is sorted or arranged, ascending order is always arranged from lowest to highest. For example, "1, 2, 3, 4, 5" and "a, b, c, d, e, f" are both arranged in ascending order.
 * The order in how information is sorted or arranged, descending order is arranged from highest to lowest. For example, "5, 4, 3, 2, 1" and "e, d, c, b, a" are both arranged in a descending order.
 * I would not have thought it necessary to explain this here, but see this diff.
 * I would not have thought it necessary to explain this here, but see this diff.


 * --Thnidu (talk) 01:14, 4 September 2016 (UTC)

Existing large tables
Many existing tables use sort keys. For example, the table in uses 309 of them. Help:Sorting admonishes us that for four types of sorting modification, "This methodology is deprecated, in favor of using",  , or both.

and  are pretty long to type. How about equivalent abbreviations, like  and  ? And 309 is a lot of changes to make in just this table; any suggestions for automating, like a bot?

Please me to discuss. --Thnidu (talk) 02:14, 4 September 2016 (UTC)

Splitting a long sortable table to display as two side-by-side sections
I am looking to make a sortable table which has a lot of rows (over 200) and instead of having it display as one long table, is there any method to have it display as two side-by-side "columns" on the page (similar to using to split lists into multiple columns) but still have it be a single sortable table? – Lestatdelc (talk) 04:48, 17 February 2016 (UTC)


 * with  works perfectly like in this table. — Sanglahi86 (talk) 22:00, 3 December 2016 (UTC)

Sort existing table with new criteria
Sorry if this is a noob question, just wondering how do you pre-sort existing table to updated new data? see: https://en.wikipedia.org/w/index.php?title=Biathlon_World_Championships_2017_%E2%80%93_Men%27s_sprint has to be pre-ordered by rank, how do u do it? Scribble scramble (talk) 08:04, 12 February 2017 (UTC)


 * Convert table to alphabetical order. Table order will not have to be changed again. --Timeshifter (talk) 23:30, 14 February 2017 (UTC)

Initial Sorting - How is it done?
There is instructions telling you that you have to sort the table before you save the page to get the default sort order you want, but nowhere does it tell how I do this. There is no "sort arrows" in the gui when you create the table. So do I need to manually move rows up and down one by one till I get it correct? Even if I only want it to be sorted by the first column? — Preceding unsigned comment added by 84.55.110.220 (talk) 12:34, 18 January 2017 (UTC)
 * That phrasing in the help page is a bit misleading; "you must sort the wikitext itself in that order" means you have to create the wikitext in the required order. Sometimes an external text editor might be helpful, but there is no standard tool in the Wikipedia editing window. -- Michael Bednarek (talk) 13:06, 18 January 2017 (UTC)


 * I clarified the info in that section: Help:Sorting. It links to more info in another section here. I clarified that section too concerning faster methods to initially sort a table. --Timeshifter (talk) 19:57, 18 January 2017 (UTC)


 * Honestly, this is stupid. So there's no way to designate the initial sort order of the table, other than just the order the rows are given in the wikitext?  E Eng  18:18, 20 February 2017 (UTC)
 * Sorting relies on client-side JavaScript. The mobile version and users without JavaScript always have the initial order and no sort arrows. It would be odd if JavaScript users saw another initial order than the permanent order for others. It would be possible to add a non-JavaScript MediaWiki feature where a table is displayed in another order than it's written but this hasn't been done. One feature I would like in the sorting is returning to the initial order after the user has sorted. This is currently only possible if one the columns sorts in the initial order. PrimeHunter (talk) 16:09, 5 March 2017 (UTC)
 * Well, I'm not sure it's that much odder than all kinds of other mobile-version inconsistencies. But that's life.  E Eng  19:30, 5 March 2017 (UTC)

Sort of the same question
In "most of" or "biggest"/"longest" (etc) types of list articles or sections, is it possible to mark a particular column as the default one, with a largest-to-smallest value already toggled?--Froglich (talk) 21:07, 10 August 2017 (UTC)
 * I think the above answers your question.  E Eng  21:09, 10 August 2017 (UTC)
 * Bleh. I penetrated the gobbledygook as far as "Honestly, this is stupid" before giving up. If the answer is a flat "no", just tell me.--Froglich (talk) 09:26, 11 August 2017 (UTC)
 * Flat no.  E Eng  12:49, 11 August 2017 (UTC)

Default sortability
Is there any reason all table headers shouldn't be sortable by default? I've seen an edge case- or two where column sorting might invite undesirable results— but surely it makes more sense for editors who can foresee those problems to obviate such circumstances rather than to deny Wikipedians of a categorical improvement in the user experience.

For example, I see no reason the table at List of most expensive association football transfers should not be wholly sortable—moreover, I see no reason to force the onus of sortability on its editors(s). — Preceding unsigned comment added by Patronanejo (talk • contribs) 02:38, 24 January 2018 (UTC)
 * There are many reasons to not make all tables sortable. To name a few:


 * 1) Some tables are used for layout, e.g. of images, and not for organizing information in columns. Sort arrows would be confusing there.
 * 2) Some columns become wider with sort arrows in the headings and would require horizontal scrolling on some screens to see the whole table.
 * 3) Some tables have a single already sorted column and the only thing sort arrows could do would be to revert the sort order, but the first click may do nothing.
 * 4) Some tables have columns that would make sense to sort but they would currently sort completely wrong due to missing sort keys.
 * 5) Some tables have colspans and rowspans where sorting would break the table.
 * PrimeHunter (talk) 02:56, 24 January 2018 (UTC)

"In a narrow space" empty headers are accessibility errors
A row of empty table headers may make columns narrower, but it's impossible to navigate and understand by keyboard and screen reader. It's also semantically nonsense so may impact SEO. A CSS or TemplateStyles solution would be more appropriate for tweaking layout. Matt Fitzpatrick (talk) 00:10, 12 March 2017 (UTC)
 * What do you mean by a CSS or TemplateStyles solution? And I assume that keyboard and screen readers have to be continually developed to keep up with what is happening on web pages. --Timeshifter (talk) 01:17, 13 March 2017 (UTC)
 * Screen readers and other accessibility tools do not have to be constantly developed to keep up with what is happening on the web pages. They do get changed from time-to-time to reflect changes to the Web Content Accessibility Guidelines. These are published by WC3 at https://www.w3.org/TR/WCAG20/. A website that is designed and developed to meet these guidelines will be accessible to users of alternate input and output tools. Designs that ignore them are the ones where trouble can occur. /Bruce/ &#91;aka Slasher&#93; (talk) 09:30, 14 March 2018 (UTC)
 * I have to say I'm sick and tired of hearing that this or that has to be a certain way because screen readers are broken. Some of these excuses I've been hearing for a decade. Fix the screen readers.  E Eng  01:47, 13 March 2017 (UTC)
 * Screen readers are not "broken" merely because they can't identify the purpose or meaning of an item. A cell with an arrow in it is just a cell containing a meaningless graphic or special character unless the designer provides meaning. Is the item an arrow? If the item is identified as an arrow, then is the arrow a control or data? If it is a control, what action is to be taken and to what data? Those are just a couple of examples. Identification of data, controls, and formatting must be provided – screen readers and other accessibility products lack the phenomenal AI and psychic power needed to figure out the designer's intentions in every situation. This is why there are design guidelines./Bruce/ &#91;aka Slasher&#93; (talk) 09:30, 14 March 2018 (UTC)
 * CSS places the sort button in the right padding of the header cell. CSS can also override that, putting the sort button anywhere else instead. See for example this page on Shoutwiki. Using only CSS, the sort buttons go either in right or bottom padding, responsive to screen width. When TemplateStyles are implemented, layouts like this become possible without an admin editing sitewide CSS. I think it might be better to wait for that than to encourage empty table cells or other HTML hacks. Matt Fitzpatrick (talk) 03:43, 13 March 2017 (UTC)
 * The Shoutwiki page has the sort icons to the right. So I don't see how that helps. It doesn't make the table narrower like putting the sorting buttons below does.
 * Is there something that can be put in the sorting cells that tells the keyboard and screen readers to ignore those cells? Is that what is wanted? I am clueless about all this. Hidden comments, CSS, etc.? --Timeshifter (talk) 14:39, 13 March 2017 (UTC)
 * The Shoutwiki example works partially for me in Firefox. With my normal window size the arrows are on the right but there is room for them without needing horizontal scrolling. If I make the window a little narrow then the arrows stay on the right even though I need scrolling to the right to see the whole table. If I make the window more narrow then the arrows move below the headers and I no longer need scrolling. PrimeHunter (talk) 15:23, 13 March 2017 (UTC)
 * While making the screen more and more narrow, is there a way to make the arrows move below the headers sooner. I did not notice the arrows drop down below the headers until long after it was necessary.
 * I guess this is part of
 * What is the code for that? I am curious to look at it.
 * I still do not understand what needs to be fixed. What does the keyboard and screen reader see that is such a problem? What does the screen reader output? --Timeshifter (talk) 20:02, 15 March 2017 (UTC)
 * Using a table to position elements on a page is just a table with stuff in it. It's lazy web design and development. There's no way for screen reader to know that the table is just a shortcut to avoid CSS formatting. It will simply say "table," followed by reading out what is in each cell, including empty cells. This is just one in a plethora of reasons why web development guidelines say don't do it./Bruce/ &#91;aka Slasher&#93; (talk) 09:30, 14 March 2018 (UTC)

In a narrow space: sorting buttons in a separate row
See this edit by User:PrimeHunter. It was done in this section:
 * Help:Sorting

There was this edit summary:


 * " this method does not work because space is reserved for sorting buttons in all header cells including cells with no button)"

I don't understand why this was done. Do you happen to know why? --Timeshifter (talk) 23:33, 13 June 2018 (UTC)
 * I don't know why and have not seen it mentioned anywhere else. I discovered it when trying to use the method. After testing four browsers with the same result I added it to the page. By the way, I used Vert header instead.[//en.wikipedia.org/w/index.php?title=Historical_rankings_of_presidents_of_the_United_States&diff=845545228&oldid=845544006#Scholar_survey_results] Maybe this option should be mentioned here. PrimeHunter (talk) 23:43, 13 June 2018 (UTC)

(unindent). Thanks for the info. I described the use of the template a little in Help:Sorting. I also put in a request for vertical headers and slanted headers on the template talk page. H e a d e r --Timeshifter (talk) 17:50, 14 June 2018 (UTC)


 * In [//en.wikipedia.org/w/index.php?title=Help:Sorting&diff=845854957&oldid=845798166] you wrote: "This method does not work with any header that spans rows or columns (rowspan and colspan)." I have addded to the documentation of Vert header that there must be no vertical bar between other attributes and the template.[//en.wikipedia.org/w/index.php?title=Template:Vert_header/doc&diff=845902885&oldid=776702678] This is common for cell formatting templates which have to add the vertical bar themselves because they add both attributes and cell content. The below example works for me in Firefox. Can the quote be removed or do you know other issues? PrimeHunter (talk) 22:39, 14 June 2018 (UTC)


 * Thanks again for the info. I updated the help page. Maybe a rowspan/colspan chart could also go on the template doc page? And/or point back here from there. --Timeshifter (talk) 17:26, 15 June 2018 (UTC)
 * A rowspan/colspan chart sounds a little off topic for Vert header documentation but I have added links to Help:Sorting and Help:Table when the concepts are mentioned.[//en.wikipedia.org/w/index.php?title=Template:Vert_header/doc&diff=846024543&oldid=845902885] PrimeHunter (talk) 19:46, 15 June 2018 (UTC)
 * Thanks. But I did not understand hardly anything you wrote in this thread except by looking at the actual table example. Developers or advanced wiki users often forget what it is like to be an average occasional wiki editor. I usually look at actual examples of any new thing on wikis. Then I usually immediately go look at the wikitext to figure it out. It has been proven that people often learn better this way. By being shown without the intermediary of arcane terminology.
 * Do you mind if I put the actual table example in Vert header documentation? --Timeshifter (talk) 05:02, 17 June 2018 (UTC)
 * I don't mind but I didn't make the template and only made a small contribution to the documentation. PrimeHunter (talk) 09:54, 17 June 2018 (UTC)

Help me please, sorting problem
On List of Madonna live performances, when we click the Title column, 3 entries (Sticky & Sweet Tour, The Virgin Tour, and Who's That Girl World Tour) is sorted improperly at the bottom of the table. When I made that table few months ago, there was not such problem. Since I'm not familiar with coding or something, I would like to ask fellow Wikipedians to help solving this problem. Thank you in advance. Bluesatellite (talk) 02:24, 20 June 2018 (UTC)
 * that's a pretty complicated table structure. The problem that I see in sorting is that the setlists are not properly attached to the row containing the more general information for the show. When sorting by title, the setlists are shown in their original order as if they all had "setlist" as their title field (or some other word between "Rebel" and "Sticky"). So the problem you have to solve is not any oddity of sorting the rows by title, that part is working just fine. What you have to solve is how to keep the setlists attached to their corresponding row. Perhaps some judicious application of  directives?
 * I'm going to leave the help me batsignal in the active state in case there are other editors who can give better advice.  — jmcgnh (talk) (contribs) 03:03, 20 June 2018 (UTC)
 * In addition, the setlist rows sort differently, depending on whether they are collapsed or expanded. I can't explain that behavior.  — jmcgnh (talk) (contribs) 05:32, 22 June 2018 (UTC)
 * Really weird, isn't it? The fact is that the sorting was really just fine when I made that table in November 2017. It seems like something has happened on Wikipedia system or something... I don't understand haha Bluesatellite (talk) 10:50, 22 June 2018 (UTC)
 * Well if it worked before, than either it worked by pure chance, or at some point someone removed the expand-child classes fixed —Th e DJ (talk • contribs) 11:25, 22 June 2018 (UTC)
 * I swear, it did work before, with all of the "setlist" rows being sorted at the bottom of the table because I put the template  on the row's header. Never mind, it looks fine now, thank you  very much  and  :) Bluesatellite (talk) 12:02, 22 June 2018 (UTC)

Table sorting by total, not year
I recently filled in the table at List of Olympic men's ice hockey players for Poland, however when sorted by tournaments it doesn't sort by year, but instead by Olympics. After some testing I found that it fixes itself if you add one name who played more than one Olympics (see User:Kaiser matias/sandbox2 as an example), but it won't work as currently stands. Anyone here have any idea how to fix it? Kaiser matias (talk) 21:12, 2 September 2018 (UTC)
 * Fixed by .[//en.wikipedia.org/w/index.php?title=List_of_Olympic_men%27s_ice_hockey_players_for_Poland&diff=857768716&oldid=857747227] It sorted as numbers before but interpreted "1972, 1976" as an 8-digit number and so on. PrimeHunter (talk) 22:15, 2 September 2018 (UTC)
 * Thanks so much. Really appreciate you're help. Kaiser matias (talk) 18:40, 3 September 2018 (UTC)

Is Template:sortname really deprecated?
Sortname was deprecated in 2015 with this edit. The same editor deprecated sort. However, this article still points to Sortname in the "see also" section. Sortname has 30,524 transclusions as of now. If it's deprecated, shouldn't it be replaced, rewritten or at least removed from the see also section? -- Aussie Legend  ( ✉ ) 13:33, 17 January 2018 (UTC)
 * It should, sort, sortname, nts, dts and any other form of using hidden sort keys, are deprecated. But people have trouble using it's replacement and thus attempts to move forward are met with outright hostility. That has created a stalemate situation. —Th e DJ (talk • contribs) 14:44, 17 January 2018 (UTC)
 * It would help to know why they are deprecated. Greenshed (talk) 01:55, 22 April 2018 (UTC)
 * Because it inserts hidden content (sometimes non-intelligble text) that gets picked up by search engines (google) and Wikipedia clients (consider Apple's Dictionary app or some screenreaders) that don't have a full understanding of our content. Abusing CSS to hide content is bad and always has been bad. Any content that is hidden in a page, should not make the site less understandable when it would be visible but this does. At some point we had WP:HiddenStructure which was also just a terrible idea and we eventually replaced it with parser functions.
 * But when people have to choose between results, convenience and correctness, well... There are several reasons i see that people are choosing to use this over the data annotation:
 * write once, read once. Basically these templates make sure you only have to enter the value once in wikitext, and also when reading the wikitext, it is sort of clear what happens.
 * People hate syntax... I've noticed a tendency to wrap just about anything into a template, so you only have to understand template syntax and be blissful in ignorance about the rest of wikitext. You see this with magicwords, basic html elements, the styling attribute etc etc.
 * Sometimes this works to the advantage, for instance with table row templates, where one method of sort annotations can easily be switched with the other, but for pure table cell entry, where you would have to write the data twice with additional wikitext markup to boot, it's just a huge barrier that people seem unwilling to climb. Not sure what else we can do. —Th e DJ (talk • contribs) 10:36, 22 April 2018 (UTC)
 * Making things easier for editors seems like a good thing to me. Isn't that one of the reasons that WPML was created - rather than just using HTML?  I have heard it said that the way Wikipedia works for editors is what Berners-Lee was aiming at for the web in general but did not quite get there.  The use of templates takes the process of simplifying editing / content creation one step further.  All that said, I guess hidden content could lead to some anomalous results but I am still not quite sure how this would happen in practice.  For example, if I write , how can this go wrong? Greenshed (talk) 00:40, 23 April 2018 (UTC)
 * produces this wikitext: . Outside tables it displays the sortkey: James Wales (British Army officer)). The sortkey is hidden in tables with code in MediaWiki:Common.css. If this code doesn't run for some reason then you also get sortkey display inside tables, e.g. if a mirror didn't copy our Common.css, or for users whose browsers didn't load it correctly, or if an administrator screws up an edit of MediaWiki:Common.css. See for example European Council with [//en.wikipedia.org/wiki/European_Council?safemode=1#Members safemode=1] which omits loading local css files. PrimeHunter (talk) 01:14, 23 April 2018 (UTC)
 * Couldn't the cause of lint-free code be much advanced if a template, say Sortname-dsv, transformed  into  ? -- Michael Bednarek (talk) 02:53, 23 April 2018 (UTC)
 * You beat me to it. I wanted to know what it was that was bad about what the template was producing so that I could suggest that we amend the template to deliver the desired results. As far as I can tell, it's not that using templates is bad, it is the way in which they are implementing the data being passed to them.  So, why can't we just amend the template to avoid the clunky and fail-dangerous Common.css approach? Greenshed (talk) 05:26, 23 April 2018 (UTC)

Adding table cell attributes is hard, since you can't easily predict where the table cell ends and starts. There is nothing guaranteeing that people have not already added other attributes like style and then explicitly started the content. Something like:  would occur quite easily and be obviously incorrect. As such it definitely isn't backwards compatible with current usages of the template, and even for a new usage, it would just be really fragile. My hope was that we would have this in the VE table editor by now, that would be the easiest solution. —Th e DJ (talk • contribs) 11:44, 23 April 2018 (UTC)
 * hmm, idea.. what if we changed the script to be able to handle . It would likely be a bit slower for the script to process that, but it might be more workable for editors. —Th e DJ (talk • contribs) 11:47, 23 April 2018 (UTC)
 * Actually.. that might already work... let's test. —Th e DJ (talk • contribs) 11:51, 23 April 2018 (UTC)
 * Seems like that will work. We will have to add a testcase to the core software to make sure it won't break in the future. But it seems like a sane adjustment. When you make the changes, be sure to remove the class=sortkey part, and the span with data-sort-value applied should preferably have the contents that you are trying to override. Note also that if there is prefix data, or postfix data to the value, that this will still be taken into account when sorting, unlike by applying the sort value to the higher up td cell (which overrides all autogenerated sort values of the content of the cell). —Th e DJ (talk • contribs) 12:14, 23 April 2018 (UTC)
 * Question that needs to be answered. Would we need to filter the sort value with scribunto's mw.text.nowiki ? —Th e DJ (talk • contribs) 12:30, 23 April 2018 (UTC)
 * Not sure I understand the rationale behind your last question but overall it seems very positive. Thanks for all your help and creativity.  Given that the script will perhaps run a bit slower, it would be interesting to see how it works with long pages (e.g. List of British Army full generals - I know it's too long but I was hoping to have worked out whether it would be better to split by British Army / [British] Indian Army or by substantive / honorary promotions). Greenshed (talk) 22:48, 23 April 2018 (UTC)
 * I have now converted sort to this structure. Let's see what happens before we do the rest. —Th e DJ (talk • contribs) 11:55, 22 June 2018 (UTC)
 * This transition is now mostly done, but nts, ntsh and convert remain. There is a testcase for this logic in core and there is a sanitation and escape module to guard against nesting and invalid characters in Module:Sortkey. —Th e DJ (talk • contribs) 12:24, 28 June 2018 (UTC)

I see that your changes to sort and sortname have stuck, but the templates are still marked as deprecated- should that be struck? -- Pres N  02:39, 23 August 2018 (UTC)
 * , I haven't really given that much thought yet honestly. I'd personally consider them 'less harmful' at the least. I also still need to do the nts series... ;( —Th e DJ (talk • contribs) 07:45, 7 September 2018 (UTC)

Sort by win-loss record
I'm trying to sort a table by win-loss record, but my first problem was that the table is treating more losses as better values, as shown in above table. I attempted to fix this by adding a data-sort-value (with -2 for an 0-2 record and 1 for a 2-1, as shown below:

However, this also had a problem, as it was unable to distinguish a 1-0 record from a 2-1 record (more wins should be better).

So my question is, is there a way to parse the string: first, forward-sort by the left number, then reverse-sort by the right number (higher number of wins is better, higher number of losses is worse)?

My goal is for the order to look like this: 0-2, 0-1, 1-2, 1-1, 1-0, 2-1, 2-0

It currently goes: 0-1, 0-2, 1-0, 1-1, 1-2, 2-0, 2-1 — Preceding unsigned comment added by Strangewrite385 (talk • contribs) 17:36, 13 October 2018 (UTC)
 * It cannot be done without a sortkey. I couldn't think of a sortkey rule which would be simple for editors so I made a complicated rule but hid it in a template which should be easy to use. See below example. Does that seem suitable? If there are cell attributes for the win-loss cell then do not make a pipe before . Just write it directly after the cell attributes. PrimeHunter (talk) 22:28, 13 October 2018 (UTC)


 * Yes, this works as I intended, thanks. Strangewrite385 (talk) 00:59, 14 October 2018 (UTC)

Sorting a table with two connected rows with no rowspan
An issue arose from this discussion where the question of if sorting is possible in Template:Episode list, as the "plot" section does not stick with its episode's row when sorted (as can be seen in the example here). Is there a way to enable sorting in this situation? I read this page but didn't find an answer. --Gonnym (talk) 16:11, 7 November 2018 (UTC)
 * Use  from Help:Sorting. For Template:Episode list it should be added to the ShortSummary row by Module:Episode list. I'm not a Lua coder. PrimeHunter (talk) 16:58, 7 November 2018 (UTC)
 * Thanks! I'll test that out! --Gonnym (talk) 17:08, 7 November 2018 (UTC)
 * It looks like you are adding the class to the cell. It should be added to the row. PrimeHunter (talk) 17:34, 7 November 2018 (UTC)
 * I'm reading up on the possible options here but so far I have no idea where to add it. I pinged the module's maintainer so hopefully he'll know where to add it. --Gonnym (talk) 17:47, 7 November 2018 (UTC)
 * You add it to the cell at  in [//en.wikipedia.org/w/index.php?title=Module:Episode_list/sandbox&diff=prev&oldid=867733258]. You should probably add it to the row at   a few lines earlier in the code, but I don't know Lua.  is a cell in html.  is a row. PrimeHunter (talk) 18:25, 7 November 2018 (UTC)
 * You were right. I connected it to the tr one and it worked. Took a few tries until I understood how the code flow worked. --Gonnym (talk) 18:59, 7 November 2018 (UTC)

Help with Template:Sortname
I went to this page for some help: Template:Sortname. I wanted to see what is the correct format to enter when a person's name contains: (A) a middle name or a middle initial; or (B) suffixes such as "Junior" or "III", etc. That page gave no examples whatsoever of such "oddities" (for lack of a better word). The page only gave a straight-forward example of a person with first name, last name. It contained no other "odd" circumstances, which are likely to arise. Can someone please edit that page to add some more illustrative examples? Specifically, what exactly to enter into the template when the person's name contains a middle name (or middle initial); and what to enter when a person's name contains a suffix (such as "Junior" or "III", etc.). Thanks. I think I was able to figure it out. But, still, the page should have more "complicated" examples, and not just the most basic and straight-forward example of "first name, last name". Thanks. Joseph A. Spadaro (talk) 14:56, 15 February 2019 (UTC)

Removal of deprecated stuff
Since no talk page yet, let's do that just to nail it down.

Yes, all of these options are deprecated and really should not be advertised here. is the best way to add a sort value. In specific, the section which is not listed as deprecated here listed as deprecated at Mediawiki:common.css and will be removed in the near future, possibly without replacement.

Now, some of the templates still do not use data-sort-value. I don't feel bad leaving a list of deprecated templates somewhere on the page for someone to review if data-sort-value does not work for their use case, but we don't need to have 10k of wikitext to explain the other deprecated methods.

It is super-obnoxious to do a full-revert because of one section which actually is deprecated, even though it does not state as such. --Izno (talk) 13:24, 23 March 2019 (UTC)
 * Support Izno's removal. There is no reason to keep documentation for a method not supported anymore. --Gonnym (talk) 13:30, 23 March 2019 (UTC)
 * OK. I see that  will work for the section in question. -- Timeshifter (talk) 22:10, 23 March 2019 (UTC)

Exclamation mark
At Help:Sorting the example below is given with explanation: "the exclamation mark ... is to clearly mark an end to the number". The example with output from Special:ExpandTemplates is: Is the advice about "!" obsolete? I can't see why it is needed with the above given the quotes around. Johnuniq (talk) 08:05, 18 April 2019 (UTC)
 * It does sound obsolete after [//en.wikipedia.org/w/index.php?title=Template:Hidden_sort_key&diff=847187654&oldid=827245308] by TheDJ. PrimeHunter (talk) 09:37, 18 April 2019 (UTC)
 * , so what the exclamation part does is terminate the number, so that JS's parseInt will stop in case another number follows the sort key directly. If you simply wrap the entire value that you want to 'mask' with sort for instance, you wouldn't have this problem. What span (or div or table-cell) with data-sort-value does, is replace the content that it wraps with the value of data-sort-value for sorting purposes. so my value 45 would become 12345. While <span data-sort-value="123!">my value 45 would be come 123!45, with stuff after 123 dropped due to the parseInt —Th e DJ (talk • contribs) 11:53, 18 April 2019 (UTC)
 * Thanks. So the exclamation mark is needed here, and data-sort-value only gives the complete sort key when it's a cell attribute like ? PrimeHunter (talk) 09:41, 19 April 2019 (UTC)
 * Amazing. I know almost nothing about JS but it seems unusual that a script could not sort with a specified sortkey. That is, I'm wondering why it couldn't just use what's in the quotes but no doubt there is a good reason. At any rate, I've put a test demonstrating the point in my sandbox (permalink). I had a lot of trouble editing and I wouldn't be surprised if the test has some blunders in it but it seems to be correct and demonstrate that the exclamation mark (or equivalent) is required. Thanks. Johnuniq (talk) 10:58, 19 April 2019 (UTC)
 * On reflection I see the logic of the script. In the context of a numeric sort, it aims to replace text such as "about 123" with "123" that will be regarded as numeric for the sort. However if several rows in the table have 123 as the sort key, whatever text follows the span will be used to determine the sort order. If the following text is something like "45 apples" then the numeric sort key will be 12345, not the specified 123. That conflicts with my experience of numeric sorting but is a defensible strategy. Johnuniq (talk) 02:04, 20 April 2019 (UTC)

@PrimeHunter: I had a wikitable heading with  that was supposed to set the sort type for the Number column. It did not work and I had to do this (put data-sort-type on its own line) to make sorting in the Number column work as wanted. Is that a known situation I should have been aware of? Johnuniq (talk) 02:04, 20 April 2019 (UTC)
 * Re  above, I added another test to my sandbox which seems to confirm that plain "123" works and no trailing exclamation mark is required. Johnuniq (talk) 09:40, 20 April 2019 (UTC)
 * I don't see the problem you describe. The Number column sorts by number both before and after the diff. And the diff only changes the pre text anyway so it should definitely have no effect on sorting. PrimeHunter (talk) 09:58, 20 April 2019 (UTC)
 * @PrimeHunter: Yikes I had a lot of problems editing those tests! I'm sure it did an alpha sort prior to my edit (which, as you point, did nothing useful!) but that might have been due to my mucking around with disabling/enabling scripting because I was getting timeouts that went away with scripting off. I put all the headings back to single line and it's good, thanks. Johnuniq (talk) 10:32, 20 April 2019 (UTC)

sortkey cleanup work left to do
Note of list of articles that require cleanup before I can fully get rid of the sortkey class being hidden. If anyone else is bored, you are welcome of course. —Th e DJ (talk • contribs) 13:58, 6 May 2019 (UTC)
 * List of Prime Ministers of Canada by time in office
 * List of Minute to Win It (Philippine game show) episodes and contestants
 * List of major springs in Florida
 * List of Latin-script keyboard layouts
 * San Francisco–Oakland–Hayward, CA Metropolitan Statistical Area
 * List of Canadian comics creators
 * List of number-one singles from the 2000s (New Zealand)
 * 2018–19 Dumbarton F.C. season
 * List of Major League Baseball players from South Korea

Question
With sorting, is there a way to sort the table before it is displayed? For example with List_of_renamed_places_in_Italy, not all the data entered was entered in alphabetical order. Rather than having to fix that manually, it would be nice to just have it sorted when the page is first displayed. Is there a parameter to do that? --David Tornheim (talk) 19:42, 1 January 2019 (UTC)
 * No. It would also make the table inconsistent—this sorting mechanism uses JavaScript, which works only in specific environments (namely only in modern browsers and the desktop version of Wikipedia, i.e. usually doesn’t work on mobile devices or outdated systems). Alphabetizing a such small table is not difficult by hand, but you can also copy it to a spreadsheet program (e.g. MS Excel) from the visual editor, sort it, and paste it back. —Tacsipacsi (talk) 21:25, 2 January 2019 (UTC)


 * N.B.: Re: the inability of mobile sorting, that seems not to be a browser problem, but more a Wiki engine problem. E.g., using same mobile browser w/ same Wikitable, I'll get no sorting on the mobile page, but, when switching to desktop page, sorting works.  Is there someplace that anyone knows where that implementation is being worked on? TSamuel (talk) 12:24, 2 June 2019 (UTC)


 * See Help:Table and the section at the end on the Visual Editor. Section called something like: "Sort table with free spreadsheet program and Visual Editor".


 * Or see Help:Sorting and the section called something like "Putting a table in initial alphabetical order".


 * I tried copying it here, but since I kept editing the help sections today, I decided to remove it from this reply. -- Timeshifter (talk) 20:11, 3 January 2019 (UTC)

How to numerically sort empty cells as positive infinity (last)
Say we have a table with a column that gives a numeric ranking, but some cells may be empty. We want unranked items to appear last rather than first in an ascending sort, because we assume unknown ranks to be worse (a higher number) than the worst known rank. Is there a cleaner (less repetitive and arbitrary) way to achieve this than putting something like  on every empty cell (as I've done in this example)? ―cobaltcigs 00:47, 19 July 2019 (UTC)
 * Leaving a cell empty isn't really helpful to readers or people that need screen readers. While it might be clear to the editors who work on it that the cell is empty because (enter reason), for a reader it can be many different reasons - didn't qualify for a score; score not yet published; score unknown; etc. So looking at this example, if you add "N/A" as an example, it sorts it last. --Gonnym (talk) 08:20, 19 July 2019 (UTC)

Time sorting oddity
I just created the page List of songs recorded by Sunn O))) and included a track length parameter for each song. For some reason—I don't know if it's just my browser or what—all songs with a track length greater than 24:00 are not sorting properly. Help! Fezmar9 (talk) 17:03, 15 September 2019 (UTC)
 * It probably read the time as hh:mm and tried to sort by time of day but couldn't handle times above 24 hours. I fixed it by sorting as text and using data-sort-value to add a leading 0 when needed.[//en.wikipedia.org/w/index.php?title=List_of_songs_recorded_by_Sunn_O)))&diff=915867443&oldid=915826113]. If natural numbers have the same number of digits then a text sort and number sort gives the same result. PrimeHunter (talk) 18:40, 15 September 2019 (UTC)
 * Awesome, thank you so much! Fezmar9 (talk) 18:43, 15 September 2019 (UTC)

Sorting in Tables on pages Saved to harddrive no longer sort
If I save a Wikipedia page to view it offline, I can no longer sort a table by clicking the first row of the column I want to sort. Does anyone know how I can get them to work offline? (I like to reduce traffic to Wikipedia by saving pages I reference often, so Wikipedia's servers don't have to send me the files multiple times a day just so I can read one number I need.) 2600:1700:8830:8DF0:21E6:FC57:BC31:2377 (talk) 07:15, 11 October 2019 (UTC)
 * Save the complete web page (HTML, javascript, etc.), not just the HTML content. (For example, in Firefox there is a "Web page, complete" option in the save dialogue box.) Mind  matrix  14:40, 11 October 2019 (UTC)
 * This doesn't make it sortable for me in Google Chrome but may work in other browsers. Sorting requires a JavaScript file to run. meta:Help:Sorting links a file. If you know how to run it in your browser when you view a html file then maybe you can use that. I haven't tried it. PrimeHunter (talk) 16:15, 11 October 2019 (UTC)
 * I got it to work in Chrome with the addon "Save Page WE". You have to enable saving scripts in "Options" -> "Saved Items" -> "Custom Items" and then on the "General" page, set "Button Action" to "Save Custom Items".  Finally I got it to work in Chrome. 2600:1700:8830:8DF0:C9FE:EECA:1F04:A2DA (talk) 12:38, 23 October 2019 (UTC)

Editing links missing from most of Help:Sorting. Problem solved
This is bizarre. It is only happening for me on Help:Sorting. Not on Help:Table or Wikipedia articles or Wikipedia talk pages.

It is the same on the 3 browsers I have checked: Firefox, Chrome, and Explorer. Latest standard version for each one. It doesn't matter whether I am logged in or not. I am using a desktop PC with Windows 10 Pro.

Edit links disappear starting with this section:
 * Help:Sorting

They don't show up again until this section:
 * Help:Sorting

I just renamed that section from "Example tables" to "Example tables. Old method" in a major edit. See diff.

It is easy to see where the edit links are missing. Log in, and search for "edit source" on the page. '''Highlight the results. Scroll down.'''

The problem is solved when I self-revert. But I can not figure out the problem. So I put back my edits because they are important, and I intend to clarify and expand on the much easier new method for adding a static row number column.

Please help. -- Timeshifter (talk) 02:19, 22 November 2019 (UTC)


 * Problem solved when I deleted unused template end brackets: }}
 * See diff.
 * I will keep this talk section so others can avoid the same weird problem. I have noticed similar problems with loose div and span tags causing problems in nested templates, etc.. -- Timeshifter (talk) 02:37, 22 November 2019 (UTC)