Page MenuHomePhabricator

Table class "sortable" incorrectly sorts a column when mixing numbers and non-numbers
Closed, ResolvedPublic

Description

I'm enclosing a wiki table that sorts incorrectly when you click the heading to sort the values. The results come out like the following. Notice that identical values (zeroes) aren't even kept together.

0
X
0
0
1
1
1
9

Here is the table in wikitext:

{| class="sortable"
|-
! Bug
|-
| 1
|-
| 1
|-
| 1
|-
| 0
|-
| 9
|-
| X
|-
| 0
|-
| 0
|}

This is in MediaWiki 1.28.0.

Details

Event Timeline

Yeah, anything that isn't valid gets value 0. I've been meaning to change that to -Infinity. Lemme submit that real quick...

Also, whenever you use sortable, you should really just tell it what datatype you expect in the column, using "data-sort-type". That avoids the sorting algorithm from having to guess, which inevitably at some point will go wrong.

Change 329673 had a related patch set uploaded (by TheDJ):
jquery.tablersorter: Sort invalid elements as -Infinity

https://gerrit.wikimedia.org/r/329673

TheDJ triaged this task as Lowest priority.Dec 30 2016, 1:16 PM
matmarex assigned this task to TheDJ.
matmarex removed a project: Patch-For-Review.

Change 329673 merged by jenkins-bot:
jquery.tablesorter: Sort invalid elements as -Infinity

https://gerrit.wikimedia.org/r/329673