Page MenuHomePhabricator

Cloned sortable tables throw JavaScript error
Closed, DeclinedPublic

Description

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


Version: 1.20.x
Severity: normal
URL: https://commons.wikimedia.org/w/index.php?title=Commons:Sandbox&oldid=74898123

Details

Reference
bz38704

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:02 AM
bzimport set Reference to bz38704.
bzimport added a subscriber: Unknown Object (MLST).

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

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