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 with more complex headers[edit]

See section higher up: #Sorting not working with complex headers. I copied this table from that section so as to focus discussion.

name Data columns Another column
data more data
cats 273 53 1
dogs 65 8,492 2
mice 1,649 548 3
{| class="wikitable sortable"
|-
! rowspan="2" | name
! colspan="2" | Data columns
! rowspan="2" | Another column
|-
! data
! more data
|-
| cats
| 273
| 53
| 1
|-
| dogs
| 65
| 8,492
| 2
|-
| mice
| 1,649
| 548
| 3
|}

I read that there is a patch being reviewed that may fix this. See comment 8 in bugzilla:38911: "Timeshifter, patch for bug 53211https://gerrit.wikimedia.org/r/#/c/98250/ – should fix that as well."

So when this table works, that means the patch code has been installed. --Timeshifter (talk) 08:07, 9 December 2013 (UTC)

Patch has been installed. I see that this table is now sorting correctly. See comment 9 in bugzilla:38911: "It has been merged now, at last." --Timeshifter (talk) 14:45, 9 April 2014 (UTC)

Sorting problem with complex table caption[edit]

I've been working for more than an hour with edit previews to make the table at Template:Boxer Rebellion sortable, but it's not working! The problem seems to come from the complex table caption, which contains the table title, an image file, and an image caption. Three different things happen depending on what code I use to introduce the table caption:

  1. When I use the recommended "|+" code, some of the caption displays outside the table and the border for the caption cell disappears.
  2. When I use a regular "|" for the caption cell, the caption displays fine, but the table becomes unsortable even if it has "class=wikitable sortable" on top.
  3. Finally when I use "!" as code, the table becomes sortable again, but the caption cell displays with the same background color as cell headers and with bold fonts on everything.

Here's my table for the third example:

{| class="wikitable sortable" border="1" align="right" style="margin-left: 1em; text-align:right;"
|-
! colspan="4" align="center" cellspacing="0" | '''Forces of the [[Eight-Nation Alliance]]<br/> <small>Relief of the [[Beijing Legation Quarter|Legations]]</small>'''<br>[[File:Troops of the Eight nations alliance 1900.jpg|300px]]<br><small><center>Troops of the Eight-Nation Alliance in 1900.<br>Left to right: Britain, United States, Australia<ref>[http://www.4808.info/html/2008-05/4469p2.html Example of Australian uniform of the period]</ref>, British India,<br> Germany, France, Austria-Hungary, Italy, Japan</center></small>
|-
! align=center | '''Countries'''
! align=center | '''Warships'''<br/> <small>(units)</small>
! align=center | '''Marines'''<br/> <small>(men)</small>
! align=center | '''Army'''<br/> <small>(men)</small>
|-
|[[Empire of Japan|Japan]] 
|18
|540
|20,300
|-
| [[Russian Empire|Russia]]
| 10 
| 750 
| 12,400 
|-
| [[British Empire|United Kingdom]]
| 8 
| 2,020 
| 10,000
|-
| [[French Third Republic|France]]
| 5 
| 390 
| 3,130
|-
| [[United States]]
| 2 
| 295 
| 3,125
|-
| [[German Empire|Germany]]
| 5 
| 600 
| 300
|-
| [[Austria–Hungary]]
| 4 
| 296
| 
|-
| [[Kingdom of Italy (1861–1946)|Italy]]
| 2 
| 80 
|
|-class="sortbottom"
| '''Total'''
| 54 
| 4,971 
| 49,255
|}

I'm not competent enough with tables to figure this out, so I'd be very grateful for your help! SFriendly.svg Cheers, Madalibi (talk) 12:11, 21 February 2014 (UTC)

This is not directly helpful, but allow me to ask: why? Why is it necessary to have a table of 8 rows sortable? I suggest that the average reader is well capable of judging the relative strengths of the alliance's members just by looking at the table. -- Michael Bednarek (talk) 13:17, 21 February 2014 (UTC)
Good point, especially since the number of ships is usually proportional to the number of troops, so that the order of countries is always about the same. But having spent so much time on this (actually much more than an hour), I'd like to know the technical solution so that I can both format this table properly and solve this kind problem in other, more complex tables in the future. Madalibi (talk) 14:07, 21 February 2014 (UTC)

class=sortkey[edit]

I use class=sortkey (in a span). Works good for me. Shouldn't it be in the doc, or is it deprecated? -DePiep (talk) 19:19, 18 April 2014 (UTC)

Can't get simple table to sort[edit]

At List of largest lakes and seas in the Solar System, I specified that the columns were to sort by "number", and set the data-sort-value for individual cells (with and without commas in the values), but I can't get the table to sort numerically. What am I doing wrong? — kwami (talk) 19:24, 24 April 2014 (UTC)

Now that the colspan parameter has been removed, it works for me. -- Michael Bednarek (talk) 03:39, 25 April 2014 (UTC)
Thanks! I never would have thought of that. — kwami (talk) 05:06, 25 April 2014 (UTC)

Chinese language names sorting[edit]

Can anyone direct me to an explanation of the Chinese language name sorting defaults used in 'wikitable sortable'? This is in connection with the article List of power stations in China (for example Coal). Thank you. Kleinzach 07:33, 8 May 2014 (UTC)

Weird purple "unsortable" table for sortable[edit]

Can someone please check List of Indian states and territories by highest point.

Am I the only one seeing the first table as an unsortable and purple colored? The second table is working fine for me.

If others are not facing this problem, any idea why I could be having it?

Thanks. Ashinpt (talk) 09:34, 19 June 2014 (UTC)

Fixed - someone had damaged the sidebar, {{Lists of states and territories of India}}. Articles using this sidebar may need a purge to have their formatting repaired. -- John of Reading (talk) 09:52, 19 June 2014 (UTC)
Gee... Thanks for your help, mate. Ashinpt (talk) 10:27, 19 June 2014 (UTC)

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)