Help talk:Sortable tables

data-sort-value with numbers
The article only talks about using data-sort-value with text. It should give examples with numbers. Main questions I had were

- do I need to surround it with quotes data-sort-value="22" or  data-sort-value=22

- do I need to (or does it help) to also manually specify the data-type Akeosnhaoe (talk) 15:29, 24 July 2023 (UTC)
 * See: Help:Sortable table (no longer works).
 * Can you provide some examples below of what you are trying to sort? A small table, for example. --Timeshifter (talk) 16:37, 24 July 2023 (UTC)
 * Visa requirements for Canadian citizens
 * As far as I can tell after doing more research, the answer to my questions were "you need to put it in quotes" and "yes", but I'm not too sure on the latter. Akeosnhaoe (talk) 16:49, 24 July 2023 (UTC)
 * data-sort-type=number is a good idea in that table because some people may forget to add the data-sort-value in some cases. This could mess up sorting in some very particular cases. Too long to explain. See the fine print here: Help:Sortable tables. And: Help:Sortable tables. --Timeshifter (talk) 17:22, 24 July 2023 (UTC)

Caption bug?
I observed a problem in instances of AchievementTable which contain a custom caption. The template includes a series of sortable columns, so upon transclusion, any custom caption added after the template will follow the columns. On standard wikitables, there is no difference if the caption is listed before or after the columns in the table design. However, in sortable wikitables, the addition of a caption after the columns causes the sorting functionality to break and the column and row dividers are missing too.

Can the code for sortable wikitables be updated to handle for caption after the columns, disregarding them from the sort? SFB 20:48, 23 August 2023 (UTC)


 * Standard wikitable, caption before columns


 * Standard wikitable, caption after columns
 * Sortable wikitable, caption before columns
 * Sortable wikitable, caption after columns


 * I would just follow the examples on Help:Table where the table caption is placed before the headers. Only between table start and first table row. Jroberson108 (talk) 21:59, 23 August 2023 (UTC)


 * . Could you give examples using AchievementTable? --Timeshifter (talk) 02:15, 24 August 2023 (UTC)
 * See previous example on Mo Farah here. This template contains parameters for defining both the table and the column, so users cannot apply a custom caption in wikitext when this template is used. I've found various cases, particularly with British athletes who naturally represent multiple nations, so I assume there are numerous instances of this in articles, but they are not easily identifiable without a manual search. I've updated the template to allow for multiple nations in the caption so the use case is covered and can be fixed by adding detail to the template parameters, but thought I'd raise this as the behaviour differs between sortable and regular wikitable. SFB 10:56, 24 August 2023 (UTC)
 * Sounds like this discussion should be moved to that template page. To clarify, what you are referring to is a table caption, which is not the same as headers in a table; otherwise it will get confusing. From the template and your recent edit, it displays a table caption of 1-2 flags/countries or, if doesn't have flag for the "nation" value, the text along with "Representing". As previously stated, the table caption has to be above all other rows including the column headers. I did a search for the code usage and found a lot where the table caption was moved to a "colspan" row of column headers, which doesn't mess up sorting. Search results. On the Christian Coleman page, there are two such tables like this: International competitions and National championships. Note that the "National championships" table doesn't show countries or flags. This improvised row of column headers would be more properly displayed as a table caption and would help with accessibility (screen readers), which is something that would need to be fixed on that template or those tables. A solution would be to add what they want displayed in the table caption along with any flags and links to the "nation" parameter, which would allow for multiple in one parameter. It would be better to discuss other solutions on that template page. Jroberson108 (talk) 22:01, 24 August 2023 (UTC)
 * Thanks for the correction! The nation parameter of that template already has a check so if something other than a nation is added (e.g. a team or club) then this will display in plain text. I'll have a think about how to best allow a "team" or "caption" option here... SFB 17:46, 25 August 2023 (UTC)
 * IMHO, I think users might be confused on the name of the parameter of "nation" ("caption" might have been better?), so doc clarity about its use in the table caption and recommended format ("the", which flag template, "&" for multiple, etc.) for consistency might help alleviate that issue. The "nation2" parameter could also be reverted if the doc is clear. This would also alleviate the need of adding additional parameters like "team" or "club" so it stays simple. Jroberson108 (talk) 18:48, 25 August 2023 (UTC)
 * The "nation" parameter has been there for nearly a decade and using it to show one national team accounts for 95%+ of usages. I've added the caption aspect this week purely because of this difference in table behaviour. It is very rarely used for non-national captions with this template. I'll add a caption parameter as an alt of nation and document that, as it already doubles for that usage anyway through the link check. SFB 20:37, 25 August 2023 (UTC)
 * I wasn't suggesting changing the "nation" parameter or the template logic around it, only documenting that it can be used for non-nations and even multiples where you would have to manually add any nation flags yourself. Adding a "caption" parameter would be clear, although the "nation" parameter also affects the table caption, so maybe specify they use one or the other. Might be good to discuss on that template's talk page with those involved? Jroberson108 (talk) 22:25, 25 August 2023 (UTC)
 * I just looked and saw you are the original creator of the template, so I guess discuss there if needed. Looks like you already added the "caption" parameter. Glad you found a solution. Jroberson108 (talk) 22:44, 25 August 2023 (UTC)

. It is good to bring such problems to both here and the template page. I have seen some buggy interactions between templates and sortable tables. For example: And between colspan and a template: So one has to find a workaround. Go with whatever works until better solutions are found. It looks like templates used at or near the top of sortable tables can be a problem. You may need to do without the template in some specific circumstances. Or the use of specific parameters may be required. Both should be listed in the template documentation. --Timeshifter (talk) 05:26, 25 August 2023 (UTC)
 * Help:Sortable tables - see note at top about sorting problem.
 * Template:Static row numbers header. Another sorting problem.
 * T344562. Row moving over one cell. Table bug using certain templates.
 * Template talk:Flagg
 * Thanks for including the context :) I've implemented support for two nations/captions in the affected template, plus inclusion of the team as column data rather than a caption. Alongside Jroberson108's other solution I think we've got enough functionality to handle all the use cases in some way! SFB 17:46, 25 August 2023 (UTC)

List of historical earthquakes
Can someone knowledgeable can lend a hand here, please: Talk:List_of_historical_earthquakes. Thanks! fgnievinski (talk) 00:44, 6 September 2023 (UTC)
 * Fixed. Jroberson108 (talk) 01:50, 6 September 2023 (UTC)

Discussion at Wikipedia:User scripts/Requests § Sortkeys in lists
You are invited to join the discussion at Wikipedia:User scripts/Requests § Sortkeys in lists. &#123;{u&#124; Sdkb  }&#125;  talk 15:40, 12 January 2024 (UTC)

Sort under template
I created the sort under template to reposition the sorting arrows under the text without the issues that come with adding sorting buttons in a separate row. Please review and mention any issues on its talk page. Jroberson108 (talk) 20:25, 28 January 2024 (UTC)

Comments are requested there specifically concerning whether the default class=sort-under should be centered sorting icons or right-aligned sorting icons. Or even left-aligned ones. --Timeshifter (talk) 21:46, 28 January 2024 (UTC)


 * For those who are interested. Someone at the technical Village Pump suggested going to this MOS discussion page since it is a style discussion, and not a technical problem. See:
 * Wikipedia talk:Manual of Style/Tables
 * --Timeshifter (talk) 14:11, 4 February 2024 (UTC)

sorting strictly alphabetically - impossible?
see Help:Sortable tables:  data-sort-type=text uses alphabetical sorting of text, but numbers are sorted numerically within that alphabetical sorting. Isn't there any possibility to get a column sorted strictly alphabetically instead of Natural sort order, so 0R11 before 0R9 ? Many thanks, Aspiriniks (talk) 11:38, 17 April 2024 (UTC) P.S. I see there was a related discussion one year ago at Help_talk:Sortable_tables/Archive_4 - any news since then? -- Aspiriniks (talk) 11:56, 17 April 2024 (UTC)
 * You might want to ask at WP:VPT or WP:Phabricator. --Timeshifter (talk) 14:44, 18 April 2024 (UTC)
 * You'll need to adjust the cell's sort value to get the desired order. For "0R9", change it to  to sort as: 0R11, 0R12, 0R9. A similar sort value would be needed for any other cell values that aren't four characters long. Jroberson108 (talk) 04:52, 19 April 2024 (UTC)

Sorting titles, some with appended text
Hello, regarding List of cult films: K, it seems like the listings The Killer and The Killing, both which neighbor listings that have longer titles starting with Killer or Killing, wind up at the bottom of each respective group when sorting alphabetically, when they should come first, having nothing after that keyword. Am I doing something wrong? Is there a way to fix it? Erik (talk &#124; contrib) (ping me) 14:24, 23 May 2024 (UTC)

I guess I fixed it by adding two spaces after each title, but this feels like too much of a hack. Is there a proper way to do this? Erik (talk &#124; contrib) (ping me) 14:26, 23 May 2024 (UTC)
 * No idea. Maybe ask at sortname too. --Timeshifter (talk) 14:50, 23 May 2024 (UTC)
 * I considered that, but it redirects to Template talk:Sort, which does not seem very active. Other suggestions for places to ask would be great. Erik (talk &#124; contrib) (ping me) 14:52, 23 May 2024 (UTC)
 * Maybe WP:VPT. --Timeshifter (talk) 15:47, 23 May 2024 (UTC)

Sorting rowspan groups with sortbottom
Sorting the following table with class=sortbottom for the bottom 2 rows removes the blank rows, displaying thusly. Qwerty284651 (talk) 21:13, 1 July 2024 (UTC)
 * The rowspan number was wrong. I temporarily added static row numbers to see that. Also, I added dashes in the blank spots in the bottom 2 rows. Both changes were needed to fix the problem. See diff.
 * An easier solution is to eliminate the blank columns. And list those years above the table. It would also make the table narrower. --Timeshifter (talk) 06:53, 2 July 2024 (UTC)
 * Yeah, that's the alternative I had with removing the years and adding a note above the table about the skipped years. Btw, why does static row display blank without bgcolor? Qwerty284651 (talk) 12:56, 2 July 2024 (UTC)

Template:Year in date-sorted table
I just created Template:Year in date-sorted table as the inverse of Template:Date table sorting. I welcome input if there are better solutions to achieve the same goal, additional features that would be useful, and or suggestions for a more descriptive template name. Daask (talk) 20:24, 16 July 2024 (UTC)
 * You might get more discussion at Help talk:Table or WP:VPT. I am not really into this now. --Timeshifter (talk) 00:27, 18 July 2024 (UTC)