Last modified: 2010-05-15 15:37:43 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T4001, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 2001 - Implement client-side sorting of table fields with JavaScript
Implement client-side sorting of table fields with JavaScript
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
Interface (Other open bugs)
1.5.x
All All
: Normal enhancement with 8 votes (vote)
: ---
Assigned To: Aryeh Gregor (not reading bugmail, please e-mail directly)
http://www.kryogenix.org/code/browser...
: patch, patch-need-review
: 494 7543 (view as bug list)
Depends on:
Blocks: javascript
  Show dependency treegraph
 
Reported: 2005-04-28 05:04 UTC by Ævar Arnfjörð Bjarmason
Modified: 2010-05-15 15:37 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Sorttable testcase (22.17 KB, text/html)
2005-04-28 05:05 UTC, Ævar Arnfjörð Bjarmason
Details
sorttable.js (6.26 KB, text/plain)
2005-04-28 05:12 UTC, Ævar Arnfjörð Bjarmason
Details
sorttable.js with fix from bug 2866 (6.32 KB, application/x-javascript)
2006-02-04 18:15 UTC, Lupin
Details
improved version of sorttable.js (5.83 KB, patch)
2006-03-04 20:18 UTC, Lupin
Details
patch to MonoBook.php to install this script (846 bytes, patch)
2006-03-04 20:21 UTC, Lupin
Details
patch to MonoBook.php to install this script (847 bytes, patch)
2006-03-04 20:22 UTC, Lupin
Details
Patch to conditionally add sorttable (8.90 KB, patch)
2006-11-14 06:08 UTC, Aryeh Gregor (not reading bugmail, please e-mail directly)
Details

Description Ævar Arnfjörð Bjarmason 2005-04-28 05:04:45 UTC
I've been toying with sorttable from kyogenix.org (under the MIT Licence) which
would display little arrows on table header fields which when clicked on would
sort the table according to that particular field (see the attached testcase).

There are some troubles with it however, it only sorts the table if it's
declared with id="unique_id" (no other element can have it) and
class="sorttable", it should preferably be modified so as to not require id=""
or the sorttable class so that it could be used for all tables.

Known bugs:

* Doesn't work for all input, numbers like "1,100" and "99" in the same column
will not get sorted correctly
* Links within the table headers will not get displayed (this is unacceptable)

I stopped working on this some time ago, posting it here as a feature request in
case somebody wants to finish it.
Comment 1 Ævar Arnfjörð Bjarmason 2005-04-28 05:05:22 UTC
Created attachment 471 [details]
Sorttable testcase
Comment 2 Ævar Arnfjörð Bjarmason 2005-04-28 05:12:30 UTC
Created attachment 472 [details]
sorttable.js

The sorttable.js file, to get it working add something like:

document.write('<script type="text/javascript"
src="/skins/common/sorttable.js"></script>');

To /skins/common/wikibits.js, to make a table sortable do something like:

{| id=foo class=sortable
! one
! two
|-
| a
| b
|-
| 2
| 1
|}


NOTE: I made a spelling error in my first post, it's class=sortable not
class=sorttable
Comment 3 Ævar Arnfjörð Bjarmason 2005-05-14 13:41:37 UTC
*** Bug 494 has been marked as a duplicate of this bug. ***
Comment 4 Arthit Suriyawongkul 2005-07-13 21:53:22 UTC
will it going to support internationalization ? thanks.
Comment 5 Antoine "hashar" Musso (WMF) 2005-07-13 23:58:55 UTC
commited to cvs.

i18n for numeric sorting can probably be achieved by getting
the "lang" attribute for the html tag and then rely on this
to set the javascript i18n.
Comment 6 T. Gries 2005-07-14 07:24:29 UTC
(In reply to comment #5)
> commited to cvs.
> 
> i18n for numeric sorting can probably be achieved by getting
> the "lang" attribute for the html tag and then rely on this
> to set the javascript i18n.

The recent change of Hashar has a negative side-effect:

on the user-login page, the username field is now corrupted.


[1]
r1=1.44&r2=1.45&f=h">http://cvs.defau.lt/cvsweb.cgi/phase3/skins/monobook/main.css.diff?r1=1.44&r2=1.45&f=h
Comment 7 Ævar Arnfjörð Bjarmason 2005-07-15 02:31:09 UTC
(In reply to comment #6)
> (In reply to comment #5)
> The recent change of Hashar has a negative side-effect: 
> on the user-login page, the username field is now corrupted.

That change got reverted, see the next diff [0], please clear your cache.

0 :
r1=1.45&r2=1.46&f=h">http://cvs.defau.lt/cvsweb.cgi/phase3/skins/monobook/main.css.diff?r1=1.45&r2=1.46&f=h
Comment 8 Brion Vibber 2005-07-15 04:32:48 UTC
Caused bug 2866; I've backed out the patch for now.
Comment 9 Lupin 2006-02-04 18:15:22 UTC
Created attachment 1365 [details]
sorttable.js with fix from bug 2866

I've applied the fix mentioned in bug 2866. I believe this should work properly
now.
Comment 10 Lupin 2006-03-04 20:18:53 UTC
Created attachment 1432 [details]
improved version of sorttable.js

This is an improved version of sorttable.js. I have cleaned up the code
somewhat, and removed the need to add an id manually, so the following should
work:

{|class=sortable
!foo
!bar
!baz
!quux
|-
|1
|z
|$12.32
|£23
|-
|2
|a
|$12000
|£1
|}

I think that only applying this to tables with class=sortable is a good thing
though, since not every table needs these funny blue arrows.

This uses the addOnloadHook function defined in wikibits.js instead of the
older code which was causing problems.
Comment 11 Lupin 2006-03-04 20:21:57 UTC
Created attachment 1433 [details]
patch to MonoBook.php to install this script

This patch installs the sorttable script for monobook users. I don't know if
this is the cleanest way to do it, though.
Comment 12 Lupin 2006-03-04 20:22:29 UTC
Created attachment 1434 [details]
patch to MonoBook.php to install this script

This patch installs the sorttable script for monobook users. I don't know if
this is the cleanest way to do it, though.
Comment 13 David Björklund 2006-08-10 23:46:13 UTC
Wow. This seem cool!

Is this still being considered for inclusion?
And how do you do with multiple classes? eg.
{| class="wikitable"
Comment 14 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-08-10 23:53:29 UTC
class="wikitable sortable"
Comment 15 David Kernow 2006-09-04 03:28:18 UTC
(In reply to comment #12)
> Created an attachment (id=1434) [edit]
> patch to MonoBook.php to install this script
> 
> This patch installs the sorttable script for monobook users. I don't know if
> this is the cleanest way to do it, though.

Okay, php know-nothing here: How do I "patch to monobook.php to install"
sorttable - create a "User:David Kernow/monobook.php" file on (say) Wikipedia
with the attachment as its content...? (Thought I ought to ask before making a
mess!) Thanks, David.
Comment 16 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-09-04 13:47:53 UTC
(In reply to comment #15)
> Okay, php know-nothing here: How do I "patch to monobook.php to install"
> sorttable - create a "User:David Kernow/monobook.php" file on (say) Wikipedia
> with the attachment as its content...? (Thought I ought to ask before making a
> mess!) Thanks, David.

You can't.  The patch has to be applied to the actual software, which obviously
users can't directly access.  You could include a version of it in "User:David
Kernow/monobook.js" by copy-pasting from the attachment on comment #10 (or using
document.write), but it wouldn't do much unless you also added class="sortable"
to various tables (or removed that condition).
Comment 17 David Kernow 2006-09-04 14:24:47 UTC
(In reply to comment #16)
> You could include a version of it in "User:David
> Kernow/monobook.js" by copy-pasting from the attachment on comment #10 ...
> but it wouldn't do much unless you also added class="sortable"
> to various tables (or removed that condition).

Thanks, Simetrical! Have pasted the sorttable.js code from comment #10 into my
monobook.js file on Wikipedia and, switching a class=wikitable table to
class="wikitable sortable", have already found that (understandably) it assumes
a table's headers are limited to the first row. Presumably a "wikitable
sortable" table will appear as a "wikitable" table to anyone browsing without
sorttable.js installed...? Thanks again, David.
Comment 18 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-10-10 23:29:57 UTC
*** Bug 7543 has been marked as a duplicate of this bug. ***
Comment 19 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-11-14 06:08:55 UTC
Created attachment 2706 [details]
Patch to conditionally add sorttable

Okay, this patch will include sorttable.js only if a table on the page actually
has a table with class sortable, so no extra 6 KB per page load.  I don't
anticipate any problems with this kind of conditional inclusion.  If there are
no objections, I'll commit this in a few days.

(Note that Lupin's modifications didn't work for me, so I just used the
original with the no-id-needed workaround.)
Comment 20 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-11-20 06:09:45 UTC
Applied in r17803.
Comment 21 Jeandré 2006-12-02 14:48:36 UTC
At
<http://en.wikipedia.org/w/index.php?title=List_of_countries_by_murder_rate&oldid=91593901>
sorting by 1998 is correct ... 1.69 2.10 ...
Reverse sorting by 1998 is by string instead of numerical: ... 2.10 19.61 ...
instead of ... 2.10 1.69 ...

Sorting by 2000 is correct, including the zero padded 2.02: ... 1.81 02.02 2.05 ...
Reverse sorting by 2000 is also correct.

Sorting 2003 is mostly correct ... 1.97 02.04 2.13 ..., only problem are the two
0s not below all the nulls.
Reverse sorting 2003 is incorrect (string): ... 2.13 15.10 ... 1.04 02.04 0.99

Sorting 2004 is pretty random, but that may be because there are certain table
blocks not defined.
Comment 22 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-12-03 02:16:19 UTC
Open a new bug, please.
Comment 23 ravedave 2006-12-05 06:25:23 UTC
Added bug 8115 for #21's comment
Comment 24 S Page 2006-12-05 07:53:36 UTC
For what it's worth, I like the presentation of table sorting in Semantic
MediaWiki 0.6 extension better than the arrows in
http://en.wikipedia.org/w/index.php?title=List_of_countries_by_murder_rate&oldid=91593901
See e.g. http://ontoworld.org/wiki/Category:Country , it uses icons for
sort_up/down/none.
The SMW sort code is derived from http://www.kryogenix.org/code/browser/sorttable/
Comment 25 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-12-05 08:46:01 UTC
I like your suggestion and added it in r18178, but please open new bugs for
future related requests.  This bug is fixed.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links