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.
 

Table not sorting at List of awards and nominations received by Game of Thrones[edit]

When I click one of the headers, the year column breaks into individual lines but nothing else happens. I'm on Chrome. Darkwarriorblake / SEXY ACTION TALK PAGE! 20:42, 10 July 2014 (UTC)

Sorting is working for me in Firefox. --Timeshifter (talk) 14:41, 11 July 2014 (UTC)
Doesn't work for me in Chrome, Firefox or IE. Darkwarriorblake / SEXY ACTION TALK PAGE! 20:41, 11 July 2014 (UTC)
I have the same behavior as Darkwarriorblake on Firefox and Chrome (on Linux) whether sorting by Category, Recipient, or Award. Almost certainly the problem is the rowspan to construct the table. —EncMstr (talk) 22:36, 11 July 2014 (UTC)

Sorting is working for me in Firefox and Internet Explorer (I don't have Chrome) in this revision of the table:

Let us check the easy stuff first. Do the previous posters have problems with complex headers? From Help:Sorting: Section titled: "Tables with complex headers":

Supposedly, people should no longer have a problem with this table below. Sorting is working for me. Is it working for you?

name Data columns Another column
data more data
cats 273 53 1
dogs 65 8,492 2
mice 1,649 548 3

If that table sorts for you, then the next step is figuring out what is happening farther down in the table in question. I am just trying to get a base line of what is working for all of us. --Timeshifter (talk) 13:52, 12 July 2014 (UTC)

Checking more revisions I see that sorting works for me (Firefox and Explorer) in this later revision:
https://en.wikipedia.org/w/index.php?title=List_of_awards_and_nominations_received_by_Game_of_Thrones&oldid=616558443
The very next revision does not have sorting working for me:
https://en.wikipedia.org/w/index.php?title=List_of_awards_and_nominations_received_by_Game_of_Thrones&oldid=616572153
Here is the diff between those 2 revisions:
https://en.wikipedia.org/w/index.php?title=List_of_awards_and_nominations_received_by_Game_of_Thrones&diff=616572153&oldid=616558443
--Timeshifter (talk) 14:04, 12 July 2014 (UTC)
I think the simple solution is to remove all the rowspans in the body of the table. See new section in Help:Sorting titled "Avoid rowspan in body of table". --Timeshifter (talk) 16:34, 12 July 2014 (UTC)
Thanks for the feedback, it was a miscounted number of rows, should've been "49" and not "50", it now appears to be working for me. I get what you're saying regarding rowspan but I think as a default, using rowspan makes the table look much more presentable, while sorting adds those individual fields in without an editor having to provide the text themselves in the code to present 2 dozen "66th Annual Emmy" fields. Darkwarriorblake / SEXY ACTION TALK PAGE! 18:39, 12 July 2014 (UTC)
Yes, but once it's done, it's done. No more stress and pain for various editors fixing this stuff over and over. Plus it allows you to better use an easy online table editor such as this one:
http://wikitable.eu5.org
Try it and see what I mean. Without rowspans it is easier to change the underlying framework of a table, and move stuff around. Once the wikitext framework is simpler, the online table editor is simpler too. Because you don't have to muck around in the wikitext frame as much. --Timeshifter (talk) 15:07, 13 July 2014 (UTC)

Which algorithm is used?[edit]

Which algorithm is used by the Wikimedia software to sort sortable tables? This question seems to be not of interest concerning practical uses, but it determines wether the sort is stable (when I have understood the term "stability" in algorithm theory correctly), and finally, it influences the user experience (a stable sorting algorithm would allow him to easily sort by various criteria simultaneously). — Preceding unsigned comment added by 2003:45:CB20:E622:3D7B:4EA5:BF9B:189E (talk) 19:47, 23 September 2014 (UTC)

You might also check out these pages, mw:Help:Sorting, m:Help:Sorting, and their talk pages. --Timeshifter (talk) 00:10, 24 September 2014 (UTC)
merge sort? Frietjes (talk) 00:14, 24 September 2014 (UTC)

Date sort apparently only working in Chrome[edit]

I have what I think is a fairly simple sortable table, Table of models with four sortable columns, two number and two date. All work fine in Chrome v37 on both Win7 (64 bit) and WinXP but the date columns don't sort in IE8/XP, IE11/Win7 or Firefox 31. The first column, Date, sorts fine in all systems. I'm thinking about going to data-sort-type="number" and using embedded sort values as a work around. Anyone else have the same problem? Any help would be appreciated? Tom94022 (talk) 21:51, 9 October 2014 (UTC)

Please have a look here: Help:Sorting#Date sorting problems --Timeshifter (talk) 07:02, 10 October 2014 (UTC)
I actually developed the Table of models based upon Help:Sorting#Year_and_month using data-sort-type="isoDate" for two columns. FWIW the three data-sort-type columns in Help:Sorting#Year_and_month all fail in the same way on my FF31/XP and IE11/Win7 systems, the directional icon at the top of the column changes state but there is no sorting. The number type sorts work. So it is either a setup problem in my two systems or a bug in the code. Since the number type seems to work I guess I will switch to that type of sort and use values to force sort order. Any idea what may be wrong - Java installations perhaps? Any one else see this problem? Tom94022 (talk) 17:39, 10 October 2014 (UTC)
I converted one column to number sort and it worked in both FF and IE11 Tom94022 (talk) 21:19, 10 October 2014 (UTC)
I think you misread Help:Sorting#Year and month. I clarified the intro to that section just now by bolding the part about "does not work". I only remember this stuff when I come back here and read what I wrote long ago. :) I only wrote some of the help page. So I am not really an expert. And I did not develop the code. You said that the number type sorts work. Number sorting has many rules. You will have to read the relevant sections carefully, and experiment. Let us know what you discover, and what needs to be changed in the help page. Please link to specific revisions in stuff you are explaining so that we are talking about the same thing. --Timeshifter (talk) 02:11, 11 October 2014 (UTC)
I guess I was fooled by the working example into misreading the note, so I rewrote it to make it clear what to avoid. Hope you approve, rewrite if you wish. As far as using data-sort-type="number" to sort dates, I just put data-sort-value="yymmdd"| Month Year into each cell and it is working so far. Thanks for supporting the article. Tom94022 (talk) 06:30, 11 October 2014 (UTC)
Thanks for clarifying the help page. --Timeshifter (talk) 07:23, 11 October 2014 (UTC)

Colspan still unsortable?[edit]

Hello,

I was trying (on the French Wikipedia) to create sortable tables with both "rowspan" and "colspan" attributes. As it wasn't working I tried tables with "rowspan" or "colspan" only. The first ones are working well, but none of the tables with "colspan" do. After some research (including information on this page) I found that "colspan" was still preventing sortable tables to work well. I'd like to know if there has been any improvement regarding this issue lately, and if not why this bug page was closed in Bugzilla while "colspan" is still breaking table sorting.

Encolpe (talk) 08:15, 14 October 2014 (UTC)

Can you link to revisions of the page with and without the problems? --Timeshifter (talk) 15:22, 15 October 2014 (UTC)
Hello Timeshifter,
For example, the first two tables on Prix Eisner. Titles ("titres") and artists ("dessinateur") sort well, but then it's chaos.
Thanks Encolpe (talk) 20:00, 15 October 2014 (UTC)
Looks like bugzilla:8028 needs to be reopened. :) The sorting code has gone through a lot of changes over the years. Please leave a message in that bugzilla thread. I don't have time. And it sounds like you have some experience trying out "rowspan" or "colspan" in various tables. --Timeshifter (talk) 02:24, 16 October 2014 (UTC)
Yes, I love to do nice tables lol
I'll try to have the bug report reopened but I'm afraid I won't be able to do anything more to help solving the problem.
Thank you for your help anyway! Encolpe (talk) 09:19, 16 October 2014 (UTC)

Hi! I created a new Bigzilla Report, still unsuccessfully so far ;) Encolpe (talk) 08:02, 2 November 2014 (UTC)

A correct table forbidden?[edit]

The help page now says: "Avoid rowspan in body of table". I find this a bit too strong. As we know, these days the rowspan is undone when a reader clicks a sortbutton (the table is turned into single-rows only with repeated cellcontent: all correct).

Indeed, adding rowspan is a complicating, but I don't see why it should be "avoided" (no exception mentioned!).

First of all, adding rowspan can be desirable before any sorting comes in play. It is a basic table feature. Second, using rowspan and sorting correctly, why not? The "avoid" 'advice' (actually to be read as a MOS guideline) does not prove that is causes errors or a wrong reader experience.

I suggest the wording is changed. There could be a warning in there, but not a scare. And to be clear, I am not planning to undo the pages where I applied rowspan in a sortable. -DePiep (talk) 08:34, 17 October 2014 (UTC)

I changed the wording so that it is less strong. Now the heading says "Difficulty of rowspan in body of table". --Timeshifter (talk) 05:29, 19 October 2014 (UTC)
OK, but the wording is a bit off too. For example, the second paragraph is about writing the correct table, which could be indeed, but that is independent of the sort option. I prefer reducing the non-sort text, and remove all scaring stuff. That is not help. -DePiep (talk)
I don't understand. What exactly is incorrect? --Timeshifter (talk) 21:39, 21 October 2014 (UTC)

Heading background color on sortable tables[edit]

bug 31775http://bugzilla.wikimedia.org/show_bug.cgi?id=31775 I'm building the List of mammals of Oregon which currently has sortable tables with a background color, but it does not have the arrows pointing up and down in the column header, like most of the other sortable tables do.

Header with color background example:

Name Species Authority Family State distribution and notes Red List
Virginia opossum
Opossum-drawing.jpg
Didelphis virginiana
(Kerr, 1792)
Didelphidae introduced early 1900s; adverse impacts on native bird populations from nest disturbances and egg consumption
7
Fl mammals lc.svg

Header with arrow but no color example:

Name Species Authority Family State distribution and notes Red List
Virginia opossum
Opossum-drawing.jpg
Didelphis virginiana
(Kerr, 1792)
Didelphidae introduced early 1900s; adverse impacts on native bird populations from nest disturbances and egg consumption
7
Fl mammals lc.svg

Is there a way to have both the arrows and the background color? Gaff ταλκ 21:29, 25 October 2014 (UTC)

I did not find a solution either. I sometimes use this compromise:

Name Species Authority Family State distribution and notes Red List
 
Virginia opossum
Opossum-drawing.jpg
Didelphis virginiana
(Kerr, 1792)
Didelphidae introduced early 1900s; adverse impacts on native bird populations from nest disturbances and egg consumption
7
Fl mammals lc.svg
Also helps me out when column titles are crammed and can use extra space. Separating the sortbuttons and text always looks nicer to me. -DePiep (talk) 01:32, 26 October 2014 (UTC)
Does not show well in mobile view (no sort buttons, so makes an empty row). -DePiep (talk) 01:32, 26 October 2014 (UTC)

Thank you. Somebody at the Help Desk showed me a solution and I came up with this:

Name Species Authority Family State distribution and notes Red List
Virginia opossum
Opossum-drawing.jpg
Didelphis virginiana
(Kerr, 1792)
Didelphidae introduced early 1900s; adverse impacts on native bird populations from nest disturbances and egg consumption
7
Fl mammals lc.svg

Gaff ταλκ 01:46, 26 October 2014 (UTC)

So one writes:
!style="background-color:#FFDEAD;"|Name
not
!style="background:#FFDEAD;"|Name
Glad to learn this. -DePiep (talk) 02:22, 26 October 2014 (UTC)
I clarified a heading in Help:Sorting concerning combining header styling and sorting. --Timeshifter (talk) 03:11, 26 October 2014 (UTC)
I added styling workaround 2 to Help:Sorting in the section concerning combining header styling and sorting. The second row of headers below the main row of headers is useful when the width of the monitor is inadequate for the number of columns. --Timeshifter (talk) 06:45, 27 October 2014 (UTC)
Why call it a workaround? Is it not a correct difference within css we usually don't notice? Or, if it is a workaround in wiki software (as the bug indicates), why bother the editor with it as an issue? Maybe a subheader like "background colors in sortable headers" would help-page visitors more.
I'll apply this to my earlier example (split sort buttons row), just to check myself. Looks OK.
Example #5 (is #3 adjusted):
Name Species Authority Family State distribution and notes Red List
 
Virginia opossum Didelphis virginiana
(Kerr, 1792)
Didelphidae introduced early 1900s; etc.
7
Fl mammals lc.svg
-DePiep (talk) 09:21, 27 October 2014 (UTC)
Yes, "Background colors in sortable headers" is a clearer heading for that section on the help page. I moved the other info to a new section called "Putting sorting buttons below header text". --Timeshifter (talk) 06:52, 29 October 2014 (UTC)

Tables with complex datarows[edit]

DePiep. You can reword stuff, but not wholesale remove whole sections as you did here. Not without discussion. We already changed the title as you requested. --Timeshifter (talk) 13:04, 10 November 2014 (UTC)

I think I see what you are trying to do, DePiep. I reworded the section and incorporated most of your wording. I shortened it and removed more of the warning tone. People now have more freedom to choose. --Timeshifter (talk) 13:26, 10 November 2014 (UTC)
Wholesale changes can be an improvement too. Being wholesale is not a reason to dismiss it.
Now, the section was not written as a help section at all. It kept repeating possible problems with rowspans and say "don't do it". That is not the topic of this page. Just note that these problems mainly exist for rowspan alone, with or without sorting. Also, the text was not a "help". And the advice to avoid rowspans always plus when sorting may be outdated because table sorting has improved enough. In short: if you build a good rowspanned table, you can add sorting.
What I wrote, and what I or any other editor expects to find here, is: if you have you rowsort OK, you can set it sortable. Not more complicated. (Must say that HELP:TABLE is not as complete on rowsort as I'd expect). Now I'll go read your edit. -DePiep (talk) 14:07, 10 November 2014 (UTC)
I removed again your copmplaints about rowspan being difficult. That is not the topic. And it is not even true. This is helptext: If you need rowspan, use rowspan. You can even sort it. -DePiep (talk) 14:12, 10 November 2014 (UTC)

Cleanup[edit]

I am performing some technical cleanup. Some issues:

  • Auto-ranking or adding a row numbering column (1,2,3) next to a table
    • Has links to user subpages
  • Default data type of a column
    • Contains: "proposed internationalisation: in German etc., treat comma as a decimal point" which makes no sense to me in its context

--  Gadget850 talk 13:21, 10 November 2014 (UTC)

I don't know anything about the German stuff. As for the linking to user pages, if it was prohibited on help pages the bots would have removed it long ago. They do so on article pages. I link to user sandbox pages from many talk pages. People use external links in the body of help pages, and not in reference format. Can help pages have subpages? If so, the row number columns can be moved there. --Timeshifter (talk) 13:33, 10 November 2014 (UTC)
Yes, subpages are enabled in the Help subspace. I don't know that there is a specific prohibition, but it is not a good idea. --  Gadget850 talk 14:24, 10 November 2014 (UTC)

Question on sorting[edit]

Letter Number
A 4
6
B 1
5
C 3
2

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 http://en.wikipedia.org/wiki/United_Nations_list_of_Non-Self-Governing_Territories#Change_in_status_by_administrating_state 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... --178.0.100.7 (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
2010
Swing
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)