Help talk:Sorting

From Wikipedia, the free encyclopedia
Jump to: navigation, search
the Wikipedia Help Project  
WikiProject icon This page is within the scope of the Wikipedia Help Project, a collaborative effort to improve Wikipedia's help documentation for readers and contributors. If you would like to participate, please visit the project page, where you can join the discussion and see a list of open tasks. To browse help related resources see the Help Menu or Help Directory. Or ask for help on your talk page and a volunteer will visit you there.
 ???  This page does not require a rating on the project's quality scale.
 ???  This page has not yet received a rating on the project's importance scale.

Question on sorting[edit]

Letter Number
A 4
B 1
C 3

In a sortable table like the above one, when you click on any column's header to sort by that column's contents the contents of the cells of the first column will be split and doubled. Is there any way to code such a table that it only splits if you sort on the second column and that if you sort back on the first column after having sorted on the second column the cells that were split in two are merged again to their original state? Tvx1 02:20, 1 March 2015 (UTC)

I don't know of any way to do that. Maybe someone else does. --Timeshifter (talk) 03:54, 2 March 2015 (UTC)
a) If a feature (row splitting in a sortable table) doesn't work as expected, don't use it; b) F5 (page refresh). -- Michael Bednarek (talk) 07:36, 2 March 2015 (UTC)
a) I know that. I have come here to ask whether there is a provision I'm not yet aware of that does allow the feature to work as intended. b) mobile devices don't have an "F5". Tvx1 19:23, 2 March 2015 (UTC)
None of the 3 browsers on my mobile phone allow any sorting of tables in Wikipedia pages at all, but they all have the Circle-redo.svg "Redo" function. -- Michael Bednarek (talk) 04:53, 3 March 2015 (UTC)

Similar problem on sorting[edit]

I have a similar problem as the one inquired above. When I sort that table in my Sandbox, Moszkowski's Op. 3 for instance, appears with Title, Opus number and Year displayed in four lines, not in one, the way it should be. The same happens with every composition containing more than one movement or key. How could I solve this problem and display Title, Opus and Year without doubling ? Krenakarore TK 23:05, 23 March 2015 (UTC)

Link? --Timeshifter (talk) 02:09, 24 March 2015 (UTC)
User:Krenakarore/sandbox Krenakarore TK 02:57, 24 March 2015 (UTC)
You might want to divide up those tables to more sandboxes. There are 2 long tables on one sandbox page. I am up to 51 sandboxes on Wikipedia: User:Timeshifter/Sandbox51. Once I link to a sandbox, I don't change its purpose. That way others can follow along later concerning past discussions. I just create more sandboxes.
See Help:Sorting#Tables with complex datarows. It says "Note that, after sorting, the rowspanning cells are cut into rows and their content is repeated." As far as I know there is no way to return to the old format except by reloading the page.
Are the columns sorting correctly? If not, then the problem is often due to not having the correct rowspan numbers. That is the problem I helped someone solve with User:Timeshifter/Sandbox51. I don't want to do that again though. Takes a long time to count the rows for each rowspan. That is why I think it can be better to avoid rowspans. Unless you inform editors how important it is count the rows, and to test sorting after any changes in the table. --Timeshifter (talk) 23:37, 24 March 2015 (UTC)
I thought it might have something to do with data-sort-values, text, numeric... something like that. For me, there should be a way to fix the rows and keep 'em fixed while in sorting mode. Op. 6 for instance, it should read Fantasie-Impromptu once, not three times. Krenakarore TK 02:14, 27 March 2015 (UTC)

Nonsensical sorting by year[edit]

When you sort this table by year the order is complete nonsense! There isn't any logic to it! WTF? Oh and yet the sorting works perfectly right in the editing preview, just not when it's saved. Still can't sort properly. In 2015... -- (talk) 11:45, 13 April 2015 (UTC)

My first impression is that population column has some cells that are blank. Not sure until I read Help:Sorting, but I think that means you will need to add data-sort-type="number" to that column head. "Year of removal" is a date column. Good luck with that. :) Lots to read in Help:Sorting on date columns. I may not have time to help much. You gotta read the manual. ;) That should get you started on your reading. --Timeshifter (talk) 17:31, 13 April 2015 (UTC)

Targets table refusing to sort[edit]

Could someone possibly have a look at what's gone wrong with the tables here (under Target seats)? The final four columns to the right sort fine in preview mode but they refuse to sort properly on the article itself. —Nizolan (talk) 23:13, 11 May 2015 (UTC)

User:Nizolan. Here is what I came up with as a solution for the top table in that section:

Conservative Party

Rank Constituency Region Winning party
required (%)
Result Swing to
CON (±%)
1 Hampstead and Kilburn London    Labour 0.10    Labour hold -1.0
2 Bolton West North West England    Labour 0.10    Conservative gain +0.9
3 Solihull West Midlands    Liberal Democrats 0.16    Conservative gain +11.9
4 Southampton Itchen South East England    Labour 0.22    Conservative gain +2.8
5 Mid Dorset and North Poole South West England    Liberal Democrats 0.29    Conservative gain +11.6
6 Wirral South North West England    Labour 0.66    Labour hold -4.8
7 Derby North East Midlands    Labour 0.68    Conservative gain +0.8
8 Wells South West England    Liberal Democrats 0.72    Conservative gain +7.4
9 Dudley North West Midlands    Labour 0.84    Labour hold -4.7
10 Great Grimsby Yorkshire and the Humber    Labour 1.08    Labour hold -5.7

I removed all the rowspans and colspans. I cleaned the table up further by removing all the sort templates. They were unnecessary. All the columns sort correctly. --Timeshifter (talk) 22:42, 15 May 2015 (UTC)

I went ahead and added the table to the article, and a note about it on the article talk page. --Timeshifter (talk) 16:34, 23 May 2015 (UTC)
A text editor's find-and-replace command speeds up fixing tables. Even Notepad (basic text editor that comes with Windows) will work. The replace command in the edit menu of Notepad. --Timeshifter (talk) 15:04, 7 June 2015 (UTC)

Default numerical sorting[edit]

Can anyone explain to a markup-challenged individual (me) why numerical list/columns default to sorting by the first digit, rather than by whole numbers? I can't think of many situations in which such a default is useful. Is this, perhaps, an unintended side-effect of alphabetical sorting?

There are quite a few broken tables out there as a result, and I (for one) find the instructions for using data-sort-type="number" difficult to follow, to say the least.

I don't know how difficult to implement this would be, but: it would save a lot of work if the in-built default sorting of digits worked differently to that of alphabetical characters. Grant | Talk 05:24, 1 June 2015 (UTC)

Please just link to the table that you need help with —TheDJ (talkcontribs) 07:49, 1 June 2015 (UTC)
I think the default is alphabetical unless a whole column only has numbers. But there are many exceptions. Empty cells for example. See the details listed in the help page. It took me awhile to figure out a few of the rules. I am not the programmer though. And a computer program has to look at a column and decide if it should be sorted alphabetically or numerically. Not an easy task, since any text in a cell means what?. Text after the number for example. :) Do you have a specific table in mind? --Timeshifter (talk) 12:42, 2 June 2015 (UTC)

Row filtering & Multiple sort fields[edit]

Is there any way to add filters on row headers to only show some of the rows in a given table. I understand that this is not trivial as it requires to adapt to each data types and to provide a minimal boolean function, but that would be a (very) nice addition to sortable tables. Along the same way it would be nice to allow sorting on multiple columns (A then B, then C). knd (talk) 09:10, 12 June 2015 (UTC)

Can you explain further? I do not understand what you are trying to do. Can you point to tables on the web that illustrate what you are trying to do? --Timeshifter (talk) 20:08, 14 June 2015 (UTC)

Numerical sorting question[edit]

I am currently working on this table. After reading the advice in this page, my understanding is that it is impossible to have the cells containing numbers sorted first, with blank/NA/- cells following afterwards. Is that correct? AtHomeIn神戸 (talk) 05:35, 23 July 2015 (UTC) Updated link since page has been moved. AtHomeIn神戸 (talk) 02:04, 2 September 2015 (UTC)

Accessibility issues when implementing "rank" in a separate table[edit]

The following note was left on my talk page, along with a revert of this version of a table:

List of countries by intentional homicide rate. Sorry to undo your edit. I know it was a lot of work. But I edit the Help:Sorting page, and understand the problems fairly well that can happen with row numbering. --Timeshifter (talk) 16:28, 27 July 2015 (UTC)

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

@Timeshifter: 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 {{efn}} and {{notelist}} 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. grolltech(talk) 18:47, 27 July 2015 (UTC)
@Grolltech: 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 phab:T42618. It supercedes phab:T42634. --Timeshifter (talk) 07:13, 15 August 2015 (UTC)