Blanks sort inconsistently in an integer column

Blanks sort inconsistently in an integer column

sbrockwaysbrockway Posts: 1Questions: 0Answers: 0
edited October 2012 in Bug reports
In the following code, when sorting on the Age column, note that the blank (Alex's age) appears between 1 and 0 when descending, and between 0 and -1 when ascending.

Shouldn't the sorting be consistent (i.e. always between 0 and 1 or 0 and -1) regardless of ascending or descending.

[code]


$(function() {
$('#sortableTableDT').dataTable({});
});




Name
Age



Bob
5


Alex



Frank
-1


Zed
0


Duncan
1


[/code]

Sort on engine version in this dataTables live example (which uses - instead of )
http://live.datatables.net/inuziv/2

Replies

  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Interesting one. Its obvious 'doh' thinking about it, so obvious, I'm surprised this hasn't come up before. Its because of this line: https://github.com/DataTables/DataTables/blob/RELEASE_1_9_4/media/src/ext/ext.sorting.js#L74 - specifically how empty strings or the dash are treated as 0. I think it should actually be `-Infinity` .

    Fix is committed here: https://github.com/DataTables/DataTables/commit/3ac3cedf535b5ee2fc5f6179ed50143878f6cc31 .

    Thanks for flagging this up!

    Allan
This discussion has been closed.