Bug: Numerical sorting with dynamically added row with 0 value is incorrectly placed.

Bug: Numerical sorting with dynamically added row with 0 value is incorrectly placed.

[Deleted User][Deleted User] Posts: 0Questions: 2Answers: 0
edited September 2014 in Free community support

Hello,

Summary:

  • Table has existing data at time of DataTable bind.
  • DataTable multiple column ordering is set on a numerical column (descending) and a date/time column (descending).
  • A new row is added via .row.add().
  • This new row contains 0 for the numerical column and the current date/time for the other column.
  • What happens: This new row with 0 for the numerical sort column appears at the BOTTOM of the table.
  • Expected: It should be above existing "0" rows because even though the numerical value is identical, the secondary column sort should place the date/time value before the existing row.

Live: http://live.datatables.net/jiraviqi/1

Instructions:

  • Click "Add Priority 1 Row". Observe row inserted above existing priority 1 rows.
  • Click "Add Priority 0 Row". Observe row inserted BELOW existing priority 0 rows. This is wrong.

I have wrote a document explaining this better, with examples at https://www.dropbox.com/s/c67d03ri5g6t1nb/sort.pdf?dl=0

Please note that this functionality worked ok in 1.8.2 using aaSorting and fnAddData.
I have tried 1.10.0 and 1.10.2 and the fault appears in both.

Currently, we are unable to use 1.10.x because of this issue.

Thanks,
Paul

Answers

  • [Deleted User][Deleted User] Posts: 0Questions: 2Answers: 0
    edited September 2014

    A friend of mine suggested the following fix:

    Change the __numericReplace function as follows:

    Change:

    var __numericReplace = function ( d, decimalPlace, re1, re2 ) {

    if ( !d || d === '-' ) {

    return -Infinity;

    }

    to

    var __numericReplace = function ( d, decimalPlace, re1, re2 ) {

    if (d !== 0 && (!d || d === '-')) {

    return -Infinity;

    }

    I tested this and it does appear to fix the problem.

    Test page at: http://live.datatables.net/zefagibe/2

    Can this be implemented in the next release please?

    Thanks

  • [Deleted User][Deleted User] Posts: 0Questions: 2Answers: 0

    Just a note to say Allan has responded to this over at GitHub for anyone following this.

    https://github.com/DataTables/DataTables/issues/414

This discussion has been closed.