User:Richardguk/Unstable tablesorter algorithm

From Wikipedia, the free encyclopedia

Copy of issue raised at Wikipedia:Village pump (technical)/Archive 98#Unstable tablesorter algorithm:

Unstable tablesorter algorithm[edit]

The current tablesorter algorith is "unstable": it does not preserve the relative order of rows where the cell content is equal.

For example, 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):

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

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 JavaScript (trunk) claims to use a merge sort algorithm, but apparently not a stable one.

Richardguk (talk) 03:53, 27 March 2012 (UTC)

Raised as bugzilla:35526. — Richardguk (talk) 18:48, 27 March 2012 (UTC)
Previous VPT report archived as VPT/Archive 98. New report by User:Astronomyinertia at Wikipedia:Village pump (technical)/Archive 101#Sort order problem. Fix proposed by User:Anomie at gerrit:15638. — Richardguk (talk) 23:30, 13 July 2012 (UTC)
Included in proposed 1.20wmf9 update (scheduled to roll out to enwiki on 13 August 2012). — Richardguk (talk) 21:05, 2 August 2012 (UTC)
Fixed, despite initial glitch with 1.20wmf9 code (fixed in Bugzilla:39296).