Last modified: 2014-08-08 09:08:07 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 T40704, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 38704 - Cloned sortable tables throw JavaScript error
Cloned sortable tables throw JavaScript error
Status: RESOLVED WONTFIX
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
1.20.x
All All
: Normal normal (vote)
: ---
Assigned To: Nobody - You can work on this!
https://commons.wikimedia.org/w/index...
:
Depends on:
Blocks: 31601
  Show dependency treegraph
 
Reported: 2012-07-26 08:51 UTC by Michael M.
Modified: 2014-08-08 09:08 UTC (History)
4 users (show)

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


Attachments

Description Michael M. 2012-07-26 08:51:30 UTC
Steps to reproduce:

1. Create a sortable table (like the one in the provided url)
2. Execute $('table.sortable').clone(true /* = with data and eventhandlers */).appendTo(mw.util.$content);
3. Click the headers of the new table.

Expected result: The table sorts correctly.
Actual result: An error is thrown: h[list[i][0]] is undefined
Comment 1 Krinkle 2012-07-26 09:27:26 UTC
I'm not a maintainer of the tablesorter plugin, but I do know (as you've found out) that the sort cache fails when applied to a different table.

Work-around:
* Don't clone including data and events, you're creating a new table essentially. So call .tablesorter() on it if you want it to be sortable.
> $('table.sortable').first().clone().appendTo( mw.util.$content ).sortable()
Comment 2 Michael M. 2014-08-08 09:08:07 UTC
(In reply to Krinkle from comment #1)
> Work-around:
> * Don't clone including data and events, you're creating a new table
> essentially. So call .tablesorter() on it if you want it to be sortable.
> > $('table.sortable').first().clone().appendTo( mw.util.$content ).sortable()

Now with mw.hook('wikipage.content') it is possible to do

$clone = $('table.sortable').clone();
mw.hook('wikipage.content').fire($clone);
$clone.appendTo(mw.util.$content);

This seems a reasonable approach to me, and I no longer consider it as just a work-around, but as an actual solution. So let's just close this as WONTFIX.

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


Navigation
Links