Author: richardg_uk
Description:
The current tablesorter algorithm is "unstable": it does not preserve (or sort consistently) the relative order of rows where the cell content is equal.
For example, in the enwiki:VPT example linked below, clicking the "Col 1" sort button twice in the table below should preserve the order of rows 2 to 8 (or invert them then restore them). But instead, the tie-break rows sort pseudorandomly (returning to the orginal order after 6 clicks instead of 2).
It is confusing for tables to change the order of rows with identical sort values. Since Wikipedia articles are not expected to contain extremely large tables, computational optimisation should be less important than intuitive operation.
The current jquery.tablesorter.js claims to use a merge sort algorithm, but apparently not a stable one.
At present, enwiki is at version 1.19wmf1 (r114429). I do not know whether this also affects versions prior to 1.19.
Live JavaScript: http://en.wikipedia.org/w/resources-1.19/resources/jquery/jquery.tablesorter.js
SVN: http://svn.wikimedia.org/viewvc/mediawiki/trunk/phase3/resources/jquery/jquery.tablesorter.js
I think Bug 31255 is a different but similar issue.
Example at: http://en.wikipedia.org/wiki/Wikipedia:Village_pump_(technical)#Unstable_tablesorter_algorithm
Wikitext of example table:
{| class="wikitable sortable"
! Col 1 Col 2 Col 3
- | ||||
aa | aba | 1 | ||
- | ||||
ab | abb | 2 | ||
- | ||||
ab | abc | 3 | ||
- | ||||
ab | abd | 4 | ||
- | ||||
ab | abe | 5 | ||
- | ||||
ab | abf | 6 | ||
- | ||||
ab | abg | 7 | ||
- | ||||
ab | abh | 8 | ||
- | ||||
ac | abi | 9 | ||
} | ||||
Version: unspecified
Severity: normal
URL: http://en.wikipedia.org/wiki/User:Richardguk/Unstable_tablesorter_algorithm