Help talk:Sorting: Difference between revisions

From Meta, a Wikimedia project coordination wiki
Content deleted Content added
ElSir (talk | contribs)
No edit summary
ElSir (talk | contribs)
No edit summary
Line 7: Line 7:
to sort by the Titel you will get a wron result. Is there any possible easy solution for this?
to sort by the Titel you will get a wron result. Is there any possible easy solution for this?


{|class="wikitable sortable"
{|class="wikitable sortable" sn=n
!Title!!State
!Title!!State
|-
|-

Revision as of 12:01, 1 September 2008


Alphanumeric Sorting

Alphanumeric sorting doesn't seem to be supported by mediawiki tables. Look at the example below. If you try to
to sort by the Titel you will get a wron result. Is there any possible easy solution for this?

Title State
Document 1 Finished
Document 2 Not Finished
Document 3 Not Defined
Document 4 Not Defined
Document 5 Not Defined
Document 6 Not Defined
Document 7 Not Defined
Document 8 Not Defined
Document 9 Finished
Document 10 Finished
Document 11 Finished

sort numerical

in the test for a numerical sort the plus (+) and minus (-) sign should be added to the match. So replace

if (itm.match(/^[\d.,]+\%?$/)) {
  sortfn = ts_sort_numeric;

by

if (itm.match(/^[\d.,\-\+]+\%?$/)) {
  sortfn = ts_sort_numeric;

and sorting of numbers works nice for numbers with sign (+1, -1, ...)

--87.163.193.10 17:44, 29 July 2007 (UTC)[reply]


Describe standard

Please restore help for standard sortable version that's used in most projects. This help page is not about meta.wikimedia.org, it's supposed to help readers with all Wikimedia projects. Modified version should be described on a separate page ∴ Alex Smotrov 13:44, 13 August 2007 (UTC)[reply]

For now I added a link to an old version of the page, from before modifications of the JavaScript were specified in MediaWiki:Common.js. However, note that for the examples to work according to the description of any version, the page describing that version should be viewed at a wiki where it applies.--Patrick (talk) 11:49, 16 August 2007 (UTC)[reply]
(In response to your answer on the talk page): at least you could explain all the differences and also list some projects currently using new code.
Do you mind if I restore (and then improve) the description of "standard" version and then move your description to, say, Help:Sorting (modified)? ∴ Alex Smotrov 14:33, 16 August 2007 (UTC)[reply]

Table with colspanned cells

Try to edit the tables in List of Colorado Avalanche players making'em sortable and show the preview. Then try to sort by name and you'll see... --82.58.27.164 13:57, 18 August 2007 (UTC)[reply]

Please provide info and/or ask a question. Perhaps you are saying that you confirm Help:Sorting#Limitations?--Patrick (talk) 00:08, 19 August 2007 (UTC)[reply]
Yes, and I think it must be fixed as soon as you can. --82.58.27.164 09:29, 19 August 2007 (UTC)[reply]

Predefined sorting

How I can make a predefined sorting? I.e., pt:Karlspreis — how I can set this table to sort by name, instead by year? Note that I mean to sort at the time of article's page is open. Slade 03:25, 16 September 2007 (UTC)[reply]

That is not possible, you have to sort the wikitext.--Patrick (talk) 11:15, 16 September 2007 (UTC)[reply]

How to specify sorting mode?

The page does not make clear how to specify the sorting mode. I had a column with entries such as "123 matches" but it was being alpha sorted. Following "the element ends with "sm=n" (without the quotes; it stands for "sort mode = numeric")", I tried sm=n in the column header's options and in the column header text without any success. However one specifies the sort mode should be clarified. (SEWilco 16:23, 20 September 2007 (UTC))[reply]

That's the biggest problem with this Help page: it's not helping users from other projects. The en.wp JavaScript version doesn't know anything about sm=n. See #Describe standard section above. I was going to rewrite the page to the standard (not Meta) version, but unfortunately I don't have the time right now. Oh, and the answer to your question: make sure all column entires start with a number or use hidden spans that start with a number ∴ Alex Smotrov 18:08, 20 September 2007 (UTC)[reply]

Isolating Columns

Is there anyway to isolate a column from the sorting function? I'm mainly interested in keeping a list of numbers (1-200) static at the side of the column while sorting various values. The numbers are there so you can compare the rank of different subjects. I know how to keep the numbers from being sortable, but I want the column to remain in order (1-200) while the other columns can be rearranged. Farside268 15:18, 8 October 2007 (UTC)[reply]

I don't think this is possible. Perhaps with two side-by-side tables, keeping the height of corresponding rows the same.--Patrick (talk) 21:30, 8 October 2007 (UTC)[reply]
I added the section Help:Sorting#Static_column on this.--Patrick (talk) 13:57, 1 November 2007 (UTC)[reply]

Headers

Is there a way to either isolate header rows within a long table to keep them from being sorted or to create a floating header row that will stay with the table as you page down? I'm trying to sort a long table – about 200 items – and it would be helpful if I could keep headers every 20-30 lines for ease of reference. Farside268 15:18, 8 October 2007 (UTC)[reply]

Infinity?

Hi folks, does anyone know whether it's possible to sort tables by columns that contain either "regular" floating point numbers or (positive) infinity? I need to work with data like that, and currently, columns that contain infinite values are treated and sorted as strings, not numbers, but that's not really helpful, of course. (BTW, right now, I'm representing infinity as "+∞", but I could certainly change that to something else like "Inf" or "+Inf" or so, too.) -- Schnee 19:37, 13 October 2007 (UTC)[reply]

Firefox problem with sorting on a column of numbers

The table in this article, when sorted on the third column, which is numerical, doesn't produce the expected (correct) result. The cause isn't obvious to me, even after reading this page, the archive of this page, and the help page itself. Could someone point out the problem?

Addendum: apparently the problem is with Firefox 2. By contrast, Opera 9 and IE7 work perfectly fine for me. Is this a known bug, or do I have some sort of setting wrong? John Broughton 15:23, 12 November 2007 (UTC)[reply]

Okay, nevermind. I fixed one number that had problems (it had commas) and the problem seems to have gone away. John Broughton 15:25, 12 November 2007 (UTC)[reply]

Default Sort?

Is it possible to cause a table to display sorted? That is, I want a table of numeric values to appear sorted when the page is loaded without having to re-order all of the table elements. Is this possible? Claytonius3 21:16, 27 November 2007 (UTC)[reply]

No, see Help:Sorting#Sorting_the_wikitext_of_a_table.--Patrick (talk) 01:21, 28 November 2007 (UTC)[reply]

Sort Direction

Is it possible to choose a default sort direction for a column? By default, a column of numbers will always be sorted from lowest to highest. If I want to sort from highest to lowest, I need to click it again. Okay, no big deal, one extra click, but say I've got a whole bunch of columns that I'd like to swap between - those extra clicks add up. The only way I can think of to make a column sort in reverse by default is to use a hidden sort key, e.g.:

Normal Sort Reverse Sort Fruit
1 91 Banana
2 55 Apple
3 28 Dill Pickle
4 64 Cucumber
5 37 Eggplant

Which, yes, it works, but gads, that's tedious. (Especially since the table I want to do this on is considerably larger than this example.) Even after I made a {{hide}} template to do all that span-stuff, it's still a pain. Is there some way to just tell that column to do a high-low sort first by default? 70.119.42.36 22:22, 11 December 2007 (UTC)[reply]

Can't get a table to sort!

I am trying to change w:List of Nintendo DS games to a sortable list. I have the work I have done so far saved here: w:User:Bse3/Sandbox. For some reason I cannot get the far right column to sort. All the other columns work just fine. I broke up the table into many sections to see where the problem is. I changed one part that was missing a line to make that section work, but when I put it all together it still will not work. Since there are many lines I could have easily overlooked something but I'm pretty sure I checked it all. I know that sort keys still need to be added for that far right column but that's another job. For now I just want the thing to do something in the first place! Hopefully someone knows what to do. Thanks. —137.186.165.215 06:09, 11 January 2008 (UTC).[reply]

Never mind. I fixed it; same problem, just missed another line. –137.186.165.215 04:25, 13 January 2008 (UTC)[reply]

Sorting problems with a table that has colspans

The table in article [1] does not sort right. It can only sorted by the first column (instead of by all colums - does this have to do with the use of colspans?), and the probably the sortbottom syntax is not used correctly. Would be nice if someone could look at it.--Ratzer 15:52, 18 January 2008 (UTC)[reply]

I took the colspans out, and changed decimal commas into points, it seems to work now.--Patrick (talk) 00:06, 19 January 2008 (UTC)[reply]
If sorting doesn't work in tables that have colspan entries (although at the end, marked as not sortable), is this a feature or a bug? :-) If it is a bug, I would like to ask the programmers to fix it.--Ratzer 09:53, 14 March 2008 (UTC)[reply]

very tricky sorting problem

Hi everybody, I would like to make this Corruption_perceptions_index sortable. I know there is a general way to make columns sortable. However, how do you make only certain columns sortable, when there is more then one row at the top? (only the columns "Rank", "Country" and the years "2007", "2006", etc. should be sortable.) While this is probably easy to solve (I hope), there is an additional twist to it. The table is split in two parts! Is it possible to have the sortable buttons only on the left side, but still make it function for the entire table? Thanx for helping out! --Spitzl 19:54, 29 January 2008 (UTC)[reply]

Making a column unsortable example not working

The Help:Sorting#Making a column unsortable example does not seem to work for me, i.e. all of the columns sort on the example. --LRG 00:46, 30 January 2008 (UTC)[reply]

Nevermind, I get it. The column still sorts, but you can not sort on the column. --LRG 00:48, 30 January 2008 (UTC)[reply]


How to Sort Dates?

When I attempt to sort the data (dates) in Table A, it gets sorted in alphabetical order ... and not in chronological date order. Is there any way to make Table A sort in correct chronological date order? Please don't tell me that I have to resort to something that looks like Table B ... or do I? Table B does indeed sort in correct chronological date order, but clearly those are unconventional (and virtually unrecognizable) date formats. Are there any alternatives at all to make this work correctly? Thanks. (Joseph A. Spadaro (talk) 07:06, 7 February 2008 (UTC))[reply]

Table A
Date of Birth
May 3, 1930
May 1, 1930
May 12, 1930
May 22, 1930
April 11, 1900
April 3, 1900
September 5, 1700
August 5, 2008
February 1, 1894
July 1, 1902
Table B
Date of Birth
1930-05-03
1930-05-01
1930-05-12
1930-05-22
1900-04-11
1900-04-03
1700-09-05
2008-08-05
1894-02-01
1902-07-01
Solution: use a hidden sortkey (explained on the help page). P.S. I believe this is yet another indication that this help page could be improved .. a lot ∴ AlexSm 14:53, 7 February 2008 (UTC)[reply]
Thanks for your reply. I do not know much about tables, charts, etc. --- other than the most very basic functions. So, to be honest, I did not understand your reply at all. Can you please clarify it for me? Thanks. Specifically ... what is a hidden sortkey and how do I employ it? ... and ... where is that help page that you are referring to? Thanks a lot. (76.239.45.253 15:04, 7 February 2008 (UTC))[reply]
Help:Sorting, this is the discussion page of that page.--Patrick (talk) 15:30, 7 February 2008 (UTC)[reply]
OK. Thanks a million. I figured it all out, with your Help. Thanks! (76.233.5.39 04:27, 8 February 2008 (UTC))[reply]

Portuguese language sorting problem

Is there anyway to sort a string column with non-english letter? For example, Á, É, Õ, etc? thanks, Charley Vasconcelos 11:39, 7 February 2008 (UTC)[reply]

Special Javascript code for this would be useful. Otherwise, use a hidden sortkey, e.g. AÁ for Á, this would position it between AZ and BA, or A, to put Áq between Ap and Ar.--Patrick (talk) 15:44, 7 February 2008 (UTC)[reply]
Thanks a lot, Patrick. Charley Vasconcelos 10:07, 8 February 2008 (UTC)[reply]

Reset Tables Original Order

How can one reset the tables original order? I've tried creating another column with the original order as numbers, but the problem is that when adding and removing items the order numbers must be updated, not a difficult task, but a tedious one when you've dealing with large lists of items. Is there either a mechanism whereby the original order can just be restored, or perhaps some sort of tag/template/extension that can create lists of numbers across table rows so that the numbers are present in HTML but need not be explicitly defined in wikitext.

Thanks. --Wahooney 13:11, 11 April 2008 (UTC)[reply]

The tables are reset by refreshing the page, depending on the browser this is e.g.done with Ctrl-F5. Apart from that, if the original order is meaningful it can probably also be obtained by sorting a column, or by adding a column with the data on which the order is based.--Patrick (talk) 00:42, 12 April 2008 (UTC)[reply]

Total row for selected columns only

Name Surname Height
John Smith 1.85
Ron Ray 1.89
Mario Bianchi 1.72
Average: 1.82

Using the example on the main page, this table had a total row. Having removed the sortbottom class, the total row is now sorted. Whilst this is silly for the Name and Surname column, it is useful for the height column. You can immediately see Mario Bianchi is below average height.

Is it possible to choose which columns the sortbottom class applies to, or is there another way to display where an average lies? ++ MortimerCat 12:00, 5 May 2008 (UTC)[reply]

Re-write with a better section layout

Please, if somebody plans to re-write this help, please do it. The issue is to separate a section for meta-specific functionality from the main body of text. The main body should provide solutions that will work almost everywhere (especially on English Wikipedia!). I'm probably yet another user that just wasted a lot of time, because sm=n just does not work. --Kubanczyk 10:35, 10 June 2008 (UTC)[reply]

Time

How can I make time, such as 12 pm, go before 10 pm and 11 pm in a sortable table? Odessaukrain 20:03, 20 July 2008 (UTC)[reply]

See Help:Sorting#Alphabetic_sorting_with_hidden_sortkey.--Patrick (talk) 09:24, 21 July 2008 (UTC)[reply]

Templates

Hello, I have a problem with sorting data from teplates in a sortable table.

Here I've used a table "wikitable sortable" to sort numeric data of two types: numbers in templates and numers without templates. The numbers in templates do not sort in the proper way. 11.434,22 precedes 377.914,78.

Please, explain me how to make these numbers in the template to sort correctly. Thank you. --Alex K 14:10, 26 August 2008 (UTC)[reply]