Help talk:Sortable tables/Archive 2
![]() | This is an archive of past discussions about Help:Sortable tables. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 | Archive 2 | Archive 3 | Archive 4 |
Can this be got working?
Vehicle | fuel consumption | max. speed | max. power | ||||
---|---|---|---|---|---|---|---|
l/100 km | mpg (imp) | mpg (US) | km/h | mph | kW | hp | |
my car | 12 | 24 | 20 | 160 | 100 | 300 | 400 |
your car | 20 | 14 | 12 | 120 | 75 | 150 | 200 |
his car | 24 | 12 | 10 | 800 | 500 | 900 | 1,200 |
her car | 10 | 29 | 24 | 80 | 50 | 90 | 120 |
In the header, it would be nice if the sort thingies were just where they're not & not where they are. Jɪmp 08:32, 27 March 2008 (UTC)
- Like this?
Vehicle | l/100 km | mpg (imp) | mpg (US) | km/h | mph | kW | hp |
---|---|---|---|---|---|---|---|
my car | 12 | 24 | 20 | 160 | 100 | 300 | 400 |
your car | 20 | 14 | 12 | 120 | 75 | 150 | 200 |
his car | 24 | 12 | 10 | 800 | 500 | 900 | 1,200 |
her car | 10 | 29 | 24 | 80 | 50 | 90 | 120 |
- Another table where this is a problem is Template:ISO 15924 script codes and Unicode as of revision 10:38, 20 May 2010. – b_jonas 21:21, 20 May 2010 (UTC)
Define column to be sorted by default
when i have !Name!!Surname!!Height: Name is sorted by default. Now I'd like to have Surname sorted by default but still as the second column. Is it possible? --Subfader (talk) 20:35, 27 March 2008 (UTC)
- I think it does not sort by default: it displays the original page in the order the wikitext is arranged. So to have it default sorted, just rearrange the wikitext. —EncMstr 21:00, 27 March 2008 (UTC)
- I had a similar need on our internal documentation wiki and having to manually sort the wiki text was not feasible in my case. It's a table of project statuses that I wanted sorted by the status column. Every time a project status changed (dev->qa for example), that meant copying/pasting the row and trying to manually keep everything in the right spot... yuck. Anyway, enough of my story. I've been fiddling with the wikibits.js and made some changes that seem to be working for us (additions in bold):
function ts_makeSortable(table) {
var firstRow;
var reverseSort = false; // flag indicating whether it should be reverse order
var defaultSortAnchor = null; // anchor tag that is the sort control for the default sort column
if (table.rows && table.rows.length > 0) {
if (table.tHead && table.tHead.rows.length > 0) {
firstRow = table.tHead.rows[table.tHead.rows.length-1];
} else {
firstRow = table.rows[0];
}
}
if (!firstRow) return;
// We have a first row: assume it's the header, and make its contents clickable links
for (var i = 0; i < firstRow.cells.length; i++) {
var cell = firstRow.cells[i];
if ((" "+cell.className+" ").indexOf(" unsortable ") == -1) {
cell.innerHTML += ' <a href="#" class="sortheader" onclick="ts_resortTable(this);return false;"><img src="'+ ts_image_path + ts_image_none + '" alt="↓"/></a>';
// if the class contains "defaultsort" then sort on this column
if ((" "+cell.className+" ").indexOf(" defaultsort ") > -1) {
// look for the "sortheader" anchor tag and use it as the sort control
var cellChildren = cell.childNodes;
for( var j = 0; j < cellChildren.length; j ++ ) {
if( cellChildren[j].nodeName == "A" && cellChildren[j].className == "sortheader" ) {
defaultSortAnchor = cellChildren[j];
}
}
// if the class contains "reverse" then do a reverse sort
if ((" "+cell.className+" ").indexOf(" reverse ") > -1) {
reverseSort = true;
}
}
}
}
if (ts_alternate_row_colors) {
ts_alternate(table);
}
// if we found a default sort anchor, then do the sort
if( defaultSortAnchor != null ) {
ts_resortTable( defaultSortAnchor );
if( reverseSort ) {
ts_resortTable( defaultSortAnchor );
}
}
}
- With this change, all you need to do to make a column sortable is put
class="defaultsort"
in the header cell of the column you want to sort on (note: if you have this on multiple columns, the last one wins). You can also add the "reverse" class if you want it to reverse sort. This is probably an inelegant solution but it's working great for us. --Aylwyne (talk) 12:39, 6 June 2008 (UTC)- Hi. i added the code
class="defaultsort"
like this: [1] but the table still does not automatically sort. Anyone know what the problem is? ќמшמφטтгמtorque 05:31, 21 August 2008 (UTC)
- Hi. i added the code
- With this change, all you need to do to make a column sortable is put
Was this ever resolved? I would also like to define the column that is the default sort, but the above class="defaultsort"
does not work. Is this code still even there?FourTildes (talk) 22:33, 4 April 2009 (UTC)
Slow - what method?
Sorting 1,000 or so items is very slow (example: list of chess grandmasters). What method does the sorting use? Could it be faster? Bubba73 (talk), 22:35, 30 March 2008 (UTC)
- It uses http://en.wikipedia.org/skins-1.5/common/wikibits.js containing in "newRows.sort(sortfn)" the sort function of Javascript itself. Thus the method used could depend on the browser.--Patrick (talk) 22:51, 30 March 2008 (UTC)
- If the input list was initially sorted, would that make it come up faster? Bubba73 (talk), 23:01, 30 March 2008 (UTC)
- JavaScript sorting is not done initially, but only after pressing the sort link, so I do not understand what you mean. Of course, putting the wikitext in the most commonly desired order is useful because it saves doing any JavaScript sorting to get that order.--Patrick (talk) 23:56, 30 March 2008 (UTC)
- When I go to list of chess grandmasters in IE7, it takes a long time for it to come up initially (but not so long in Firefox). I was wondering if it was initially running the sort, which is taking a long time. But if it doesn't sort until someone click, then that can't be it. Is there anything simple that can be done to make that article come up faster? Bubba73 (talk), 15:02, 31 March 2008 (UTC)
- The slow load time is a consequence of all the flag templates. Remove them and it will be much faster. — Andrwsc (talk · contribs) 20:36, 1 April 2008 (UTC)
- When I go to list of chess grandmasters in IE7, it takes a long time for it to come up initially (but not so long in Firefox). I was wondering if it was initially running the sort, which is taking a long time. But if it doesn't sort until someone click, then that can't be it. Is there anything simple that can be done to make that article come up faster? Bubba73 (talk), 15:02, 31 March 2008 (UTC)
- ::::: I thought that might be the case, and it was discussed on the article's talk page, but someone did a test and they found that the flags were not the problem. (See list of chess grandmasters talk page.) Bubba73 (talk), 20:43, 1 April 2008 (UTC)
- It's not clear from the talk page discussion what browsers were used for that test, but it is a known problem that special code added to MediaWiki:Common.js for PNG images (which is how flag icons are thumbnailed on server caches) slows IE page loads. In any case, I think you might be better off without flags on that page anyway, for WP:Manual of style (flags) issues. — Andrwsc (talk · contribs) 21:04, 1 April 2008 (UTC)
- Right. I first noticed the slowness problem with IE7. Then when I tried Firefox it was much faster. Thanks for the MoS link - I had already questioned whether there should be flags or not. Bubba73 (talk), 22:30, 1 April 2008 (UTC)
static columns
Is there a way of disabling sorting on one or more columns? I see the static columns example but it's not ideal building it with two separate tables.
Anyone? Cnbrb (talk) 21:50, 9 April 2008 (UTC)
- I don't think there's any supported method. There's probably some way to do it by hiding the handles, but I don't know how. Why do you want to disable sorting some columns? —EncMstr 22:07, 9 April 2008 (UTC)
Thanks - sometimes I have a table where a reader might want to sort (say) column 1 alphabetically but subsequent columns might not be something worth sorting (e.g. a notes column). Hiding the handles would be the kind of thing I was thinking of. Cnbrb (talk) 23:15, 9 April 2008 (UTC)
- Even sorting a notes column is useful to collect the rows which have a note entry—and the same note. If that seems haphazard, revising the note entries to make them more friendly, perhaps with standard leading keywords or tags. Granted, there are a few tables where the columns make little sense to sort, but that's hardly a reason to prevent it. Perhaps someone, somewhere has a use. —EncMstr 23:38, 9 April 2008 (UTC)
- I think I have a use. In the table at List of Royal Air Force air chief marshals, I would like to create a new column on the left hand side which no matter which of the sortable columns has been clicked, it always displays 1, 2, 3, 4, ... This would enable readers to rapidy work out who was promted 20th (say) or had the 65th (say) longest time in rank etc. Any ideas on how to do this (apart from 2 nested tables which will not really work as the row hight in the right-hand sub table varies)? Thanks Greenshed (talk) 23:35, 27 November 2009 (UTC)
Requesting to view wikitable code for Help:Sorting#Examples
I'd like to view the code for several examples used at Help:Sorting#Examples However, that page is protected from editing. Is there another location where the code is able to be viewed?
Specifically, I would like to see the wikitable code for the very last example which should show how to correctly use the "sm=n" solution for forcing numerical sort.
Quote:
- Sortable version of Template:Climate in Middle East cities, using smn to specify numeric sort mode
Najevi (talk) 15:09, 20 April 2008 (UTC)
Ha! Found the source code at http://meta.wikimedia.org/wiki/Help:Sorting#Examples
| style="text-align:center;" |-3°C{{smn}} | style="text-align:center;" |7°C{{smn}}
Najevi (talk) 15:21, 20 April 2008 (UTC)
Only some of the numbers will sort
In the article International wheat production statistics, years 2002-1999 work fine, while years 1998-1996 don't sort correctly. Is there any way to fix this, or is this a known "bug"? Esn (talk) 04:49, 23 April 2008 (UTC)
- Hold on, I think I see what is causing it. The problem columns all have the entry "0NA" (signifying "negligible" or "not on the list in that year"). Is there any way to say "n/a" in a table without saying "0" (which wouldn't technically be correct)? Esn (talk) 04:53, 23 April 2008 (UTC)
Please help: Sortable table provides one round of correct sorting, another of incorrect sorting
Try this: visit the birth control comparison table, and click the button to sort by "perfect use" rates, once. Only once. See the two "no data" items at the top, there? OK, now click it again: what's happening is that it is being sorted in a different way. I don't know the name for it, but if you look at the very top of the block of blue items in "perfect use", and start moving your eyes up line by line, you will see it go from 2 to to 20 to 26. Clearly it is being sorted in a way that make mathematical sense, but is useless for that table's intended comparison. Is there a way to make the sortable table not do this? Thanks! Whistling42 (talk) 02:45, 25 April 2008 (UTC)
- Interesting. I speculate that it determines the type of comparison (string or numeric) to use by looking at the first element in the table. Once it's sorted so that "no data" is on top, it then uses a string comparison. To fix, use the
{{sort|<what to sort by>|<what you see>}}
template. For the no data, I expect the sort key would be 0 (zero). —EncMstr (talk) 02:53, 25 April 2008 (UTC)
- Thanks for your response. I understand, somewhat, but I don't know what you mean by "first element in the table". It is definitely switching between numeric and string. I'm not really sure how to use the template; in my previews (using the Sort template) using 0, 100, and a blank space, it still didn't work properly. Any ideas? Care to tinker with it? The only method I found that works is to remove the "no data" and "see note" text entirely, but I would rather keep the text if there is a way. Whistling42 (talk) 03:42, 25 April 2008 (UTC)
- This diff shows the changes I intended. I keep meaning to look up how to make {{sort}} not use a string comparison, but I just padded it with leading zeros and made it work okay. If you don't like "no data" sorting as though its value is zero, it should be clear now how to change that. —EncMstr (talk) 04:08, 25 April 2008 (UTC)
Error on Mediawiki version ?
On the help page says "This works in MediaWiki 1.9 and above", but on MediaWiki, the las version is: "2008-03-20: 1.12.0 quarterly release". So we should wait some month for 1.9 version, and all Mediawiki projects has a very unstable version!? —Preceding unsigned comment added by 190.18.45.41 (talk) 02:22, 14 May 2008 (UTC)
- The versions are sorted weirdly. Version 1.12.0 is "above" 1.9, that is, 1.12.0 was released after 1.9. You might check out mw:Version lifecycle for information on the releases. JackSchmidt (talk) 04:55, 14 May 2008 (UTC)
helpful
This page was very helpful! thanxArdeshire Babakan (talk) 18:10, 24 July 2008 (UTC)
Do not edit this copy?
This is a copy of the master help page at Meta. Do not edit this copy.
That is what I see at the top of the article Help:Sorting, followed by
Edits will be lost in the next update from the master page.
Yet I see that edits have been made to the copy and do not see any update. Is this an old out of date message? It confused me, because I first read the sort mode section (ignoring the top message out of habit) and read the "sm=n" and "m:Template:smn". I found smn does not work for me, so I look at meta:Help:Sorting , where smn mention has recently been removed. Does this mean this copy page is due an update?
Also, at the very end I see: "In particular, both the Template:Smn and the sm=n trick do not work on Wikipedia." -84user (talk) 03:56, 5 October 2008 (UTC)
Numeric sort test
This table should sort according to wikipedia's Help:Sorting but not according to according to meta:Help:Sorting (maybe because meta has removed the support for formats like 4.32×104). Today it does not sort properly.
numbers might not sort |
---|
123564589.7e12 |
9 |
4.32×104 |
-80 |
5.67 |
80 |
70 |
600 |
This table should sort according to both wikipedia and meta, and do sort for me today:
numbers should sort |
---|
123564589.7e12 |
9 |
4.32e4 |
-80 |
5.67 |
80 |
70 |
600 |
-84user (talk) 03:56, 5 October 2008 (UTC)
Sorting Negative Numbers
Sorting negative numbers seems to work when the ASCII hyphen/minus "-" (0x002D) is used. It seems that the problem may be caused by the Unicode Minus Sign "−" (0x2212). - Unimath (talk) 00:13, 11 October 2008 (UTC)
- Interesting. The tables above use standard ASCII minus and the second one sorts correctly numerically. Let's test sorting with a Unicode Minus Sign here:
do numbers with Unicode Minus Sign sort Ok? |
---|
123564589.7e12 |
9 |
4.32e4 |
−80 |
5.67 |
80 |
70 |
600 |
- Results: With Unicode minus the above table sorts with this cycle: 1. numeric descending, 2. numeric ascending, 3. alphabetic descending, 4. alphabetic ascending, and repeat. So you are right - unicode breaks sorting. -84user (talk) 10:40, 11 October 2008 (UTC)
Center
How do you make a box be placed in the center? — NuclearVacuum 23:52, 27 November 2008 (UTC)
Max rows for sort = 50?
Is there a maximum on the number of rows displayed for a sorting table? I have a table with 54 rows, and only the first 50 display. Those work fine, I just need the last 4 to show. Thanks in advance, Chuckiesdad (talk) 06:13, 30 November 2008 (UTC)
- Withdrawn by original poster, there are lots of functional sorting tables with hundreds of entries, so this is not a Wiki problem, I'll check my browser and editor for bugs. Regards, Chuckiesdad (talk) 22:18, 30 November 2008 (UTC)
numeric sort with 1+ non-numeric elements doesn't work on firefox 3.0.4
It seems that if there are one or more 'non-numeric' elements in an otherwise numeric column, then it does not sort properly in firefox 3 (I tested with 3.0.4 on windows xp). You can see this on the first 'numbers' table in the Help:Sorting page (with 'ghi' as one of the elements).
Additionally, in IE6 and IE7, after the page first loads and you try to sort a table of the aforementioned description, a first click on the sort button will not properly sort the table. The second and subsequent clicks seem to work properly. You can also see this problem here: United States cities by crime rate by sorting by 'violent crime'. —Preceding unsigned comment added by Tfischer (talk • contribs) 20:51, 15 December 2008 (UTC)
Could somebody take a look at this article?
I am trying to merge some wrestling title articles per a AFD discussion. The problem I am having is with the autosorting (since I am merging articles that existed just for how long they held a title with a list of chronological champions, so there has to be a way to sort based on how long they held the title). I can't seem to get it working right now. The article is List of WWE Intercontinental Champions. Could somebody experienced with autosorting take a look at it for me? TJ Spyke 05:38, 21 December 2008 (UTC)
Sorting diacritic letters
What is the correct sorting order for words and names with diacritic letters? Various languages using the Latin alphabet sort their diacritic letters differently. In Swedish for instance, Å, Ä and Ö are the final letters of the alphabet. I assume that words with diacricits should be sorted without them, but I can't find any wikipedia rule about this. In one help page ASCII is stated to be the sorting order for strings, but that would be a bit confusing since diacritics are not placed next to their "main" letters. Mad Greg (talk) 12:15, 28 December 2008 (UTC)
Blank spaces treated as zero
I am struggling to find a solution to the sortable table at List of Calgary Flames draft picks that would allow the list to sort empty cells as being less than zero. I could use {{sort|-1| }} in each cell, but in a table of this size, it would introduce a massive amount of overhead. In fact, in testing that as a solution I found editing the table to be incredibly difficult as both IE and Firefox struggled to handle the amount of data. Unfortunately, using emdashes rather than blank cells only managed to completely break sortability. Does anyone have any suggestions on how to resolve this problem? Thanks, Resolute 23:54, 12 February 2009 (UTC)
Filterable
Hi guys, is there a way to make tables in wikipedia filterable?
Similar to this: http://mguglielmi.free.fr/scripts/TableFilter/filter-sort.htm --TheBigJagielka (talk) 00:10, 30 April 2009 (UTC)
Synch this copy with the one on meta?
This version of Help:Sorting lacks many good updates that have been made to meta:Help:Sorting. For example, the confusing business about "sm=n" has been removed from meta's copy. Should these differing versions be synchronized now? --fjarlq (talk) 09:51, 9 May 2009 (UTC)
- Per m:Help talk:Sorting#Synch this copy with the one on en?, I have manually synched this up with meta. --fjarlq (talk) 10:55, 13 May 2009 (UTC)
Sorting with dates before 10,000 BC
It seems that the method for date sorting only works for dates after 10,000 BC. How do I make a sortable column for dates before that date? In the table in question, I have dates from before 10,000 BC until around 800 AD. As the table is still in preparation, I am not sure yet what the exact dates will be. Most likely I will not have any month/day information to sort though. bamse (talk) 02:56, 13 May 2009 (UTC)
Filter OUT, not IN
What I'd like to see is a way to pick one cell and filter OUT every row with that value in that column. This should be repeatable (same or different columns), without adding back the items filtered out (until you click refresh or something). This way you could start with a large list and gradually remove items that fail one or another criteria, until you've got the list whittled down to just the items that are truly interesting.
Ideally sorting would NOT interfere with this; it would simply sort the items you have not filtered out. —Preceding unsigned comment added by 74.166.109.199 (talk) 01:30, 21 May 2009 (UTC)
The "Sorting the wikitext of a table" section
I don't understand this section at all. What is it saying? Is there something wrong with the markup or is it supposed to look like that?
Additionally, is it possible to create a table that is sorted by one of its columns by default? Shreevatsa (talk) 19:27, 25 May 2009 (UTC)
- I repeat the question of Shreevatsa verbatim. Someone please answer! (I think the help page should have a header "sorting tables by default," even if the content is, "it can't be done.") Andrew Gradman talk/WP:Hornbook 20:49, 1 August 2009 (UTC)
- Ah yes, I understood shortly after posting here that it was describing a clever (or stupid) hack that lets you use Wikipedia itself to sort the wikitext of a table. I've also added a section on "Sorting tables by default" with the content saying "it can't be done", per your suggestion. Shreevatsa (talk) 21:37, 1 August 2009 (UTC)
Clicking the Sort button jumps to top of page
Does anyone know what is going on here? In this article, only the first five columns of the table in section 5 (history) are sortable. The last buttons cause a jump to the start of the page for some strange reason. --KarlFrei (talk) 09:53, 26 June 2009 (UTC)
- I don't know what the problem with this specific table is, but I noticed the same problem if I don't specify a column entry. See the example below.
sorts:
A | B |
---|---|
a | b |
c |
good code:
{| class="wikitable sortable" border="1" |- ! A ! B |- | a | b |- | c | |}
does not sort:
A | B |
---|---|
a | b |
c |
bad code (second last line is missing):
{| class="wikitable sortable" border="1" |- ! A ! B |- | a | b |- | c |}
bamse (talk) 10:58, 26 June 2009 (UTC)
- Thanks! I have now realized that the problem was due to a cell spanning multiple columns. --KarlFrei (talk) 13:09, 26 June 2009 (UTC)
JavaScript sentence poorly written
As of 26 June 2009 the first sentence under the JavaScript section is confusing and doesn't appear to be proper English:
"The JavaScript code wikibits.js has on each site a copy at {{SERVER}}/skins-1.5/common/wikibits.js, on this site http://en.wikipedia.org/skins-1.5/common/wikibits.js."
Unjedai (talk) 14:57, 26 June 2009 (UTC)
I'll try again. What is the above sentence trying to say? What is the point? Is it trying to say that the JavaScript necessary to make table sorting work is installed with MediaWiki 1.9 and above versions in the {{SERVER}}/skins-1.5/common/wikibits.js directory, and that, for example on Wikipedia the URL for that is http://en.wikipedia.org/skins-1.5/common/wikibits.js? Unjedai (talk) 18:25, 23 September 2009 (UTC)
- I think that's what it's trying to say, yes. Don't see why it's necessary to say that, though. Shreevatsa (talk) 19:33, 23 September 2009 (UTC)
- I think it's helpful because for some reason sorting isn't working on my wikis and this may help me know where to look for the problem. But I propose rewording it like this: "The JavaScript necessary to make table sorting work is at {{SERVER}}/skins-1.5/common/wikibits.js for each site. For example, on Wikipedia the URL is //en.wikipedia.org/skins-1.5/common/wikibits.js." Unjedai (talk) 15:33, 8 October 2009 (UTC)
Why is sort type not specified in column header?
It would be much less error prone to specify the sort type in the column header itself (similar to class="unsortable"). I propose class="date|numeric|currency|string|unsortable" in the header template to override determining a sort order by parsing the first cell in the table. This would fix many, many sorting bugs due to some rows containing bad data, such as "", "123±5" or "15—17" not being seen as numeric. --IanOsgood (talk) 18:44, 5 July 2009 (UTC)
- I see someone has already proposed a similar patch (class="sort-*"). I heartily approve. What will it take to get it into mainline? --IanOsgood (talk) 18:57, 5 July 2009 (UTC)
Why....?
Why, on New Zealand firefighter referendum, 1995, does it sort some percentages funnily, particularly in the 'no' column? If someone could fix this or tell me how to fix it, I would be very appreciative.Adabow (talk) 01:50, 17 July 2009 (UTC)