Implement client-side sorting of table fields with JavaScript
Closed, ResolvedPublic

Assigned To
None
Priority
Normal
Author
bzimport
Commits
Unknown Object (Commit)
Subscribers
Thryduulf, Wikinaut
Projects
Reference
bz2001
Description

Author: avarab

Description:
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.


Version: 1.5.x
Severity: enhancement
URL: http://www.kryogenix.org/code/browser/sorttable/

bzimport added a project: MediaWiki-Interface.Via ConduitNov 21 2014, 8:26 PM
bzimport set Reference to bz2001.
bzimport created this task.Via LegacyApr 28 2005, 5:04 AM
bzimport added a comment.Via ConduitApr 28 2005, 5:05 AM

avarab wrote:

Sorttable testcase

Attached: sort.html

bzimport added a comment.Via ConduitApr 28 2005, 5:12 AM

avarab wrote:

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

attachment sorttable.js ignored as obsolete

bzimport added a comment.Via ConduitMay 14 2005, 1:41 PM

avarab wrote:

*** Bug 494 has been marked as a duplicate of this bug. ***

bzimport added a comment.Via ConduitJul 13 2005, 9:53 PM

arthit wrote:

will it going to support internationalization ? thanks.

hashar added a comment.Via ConduitJul 13 2005, 11:58 PM

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.

Wikinaut added a comment.Via ConduitJul 14 2005, 7:24 AM

(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]
http://cvs.defau.lt/cvsweb.cgi/phase3/skins/monobook/main.css.diff?r1=1.44&r2=1.45&f=h

bzimport added a comment.Via ConduitJul 15 2005, 2:31 AM

avarab wrote:

(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 :
http://cvs.defau.lt/cvsweb.cgi/phase3/skins/monobook/main.css.diff?r1=1.45&r2=1.46&f=h

brion added a comment.Via ConduitJul 15 2005, 4:32 AM

Caused bug 2866; I've backed out the patch for now.

bzimport added a comment.Via ConduitFeb 4 2006, 6:15 PM

lupin.wp wrote:

sorttable.js with fix from bug 2866

I've applied the fix mentioned in bug 2866. I believe this should work properly
now.

attachment sorttable.js ignored as obsolete

bzimport added a comment.Via ConduitMar 4 2006, 8:18 PM

lupin.wp wrote:

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.

Attached: s.js

bzimport added a comment.Via ConduitMar 4 2006, 8:21 PM

lupin.wp wrote:

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.

attachment s2 ignored as obsolete

bzimport added a comment.Via ConduitMar 4 2006, 8:22 PM

lupin.wp wrote:

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.

attachment s2 ignored as obsolete

bzimport added a comment.Via ConduitAug 10 2006, 11:46 PM

david.bjorklund wrote:

Wow. This seem cool!

Is this still being considered for inclusion?
And how do you do with multiple classes? eg.
{| class="wikitable"

bzimport added a comment.Via ConduitAug 10 2006, 11:53 PM

ayg wrote:

class="wikitable sortable"

bzimport added a comment.Via ConduitSep 4 2006, 3:28 AM

davidkernow wrote:

(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.

bzimport added a comment.Via ConduitSep 4 2006, 1:47 PM

ayg wrote:

(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).

bzimport added a comment.Via ConduitSep 4 2006, 2:24 PM

davidkernow wrote:

(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.

bzimport added a comment.Via ConduitOct 10 2006, 11:29 PM

ayg wrote:

*** Bug 7543 has been marked as a duplicate of this bug. ***

bzimport added a comment.Via ConduitNov 14 2006, 6:08 AM

ayg wrote:

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.)

Attached: 2001.patch

bzimport added a comment.Via ConduitNov 20 2006, 6:09 AM

ayg wrote:

Applied in r17803.

bzimport added a comment.Via ConduitDec 2 2006, 2:48 PM

jackdt wrote:

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.

bzimport added a comment.Via ConduitDec 3 2006, 2:16 AM

ayg wrote:

Open a new bug, please.

bzimport added a comment.Via ConduitDec 5 2006, 6:25 AM

davidcraig5 wrote:

Added bug 8115 for #21's comment

bzimport added a comment.Via ConduitDec 5 2006, 7:53 AM

info wrote:

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/

bzimport added a comment.Via ConduitDec 5 2006, 8:46 AM

ayg wrote:

I like your suggestion and added it in r18178, but please open new bugs for
future related requests. This bug is fixed.

matmarex added a project: JavaScript.Via WebDec 21 2014, 7:07 PM
epriestley added a commit: Unknown Object (Commit).Via DaemonsMar 4 2015, 8:24 AM

Add Comment

Column Prototype
This is a very early prototype of a persistent column. It is not expected to work yet, and leaving it open will activate other new features which will break things. Press "\" (backslash) on your keyboard to close it now.