Filter breaks sorting

Filter breaks sorting

koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
edited October 2013 in DataTables 1.9
I have a 1.9.4 datatable (which is encapsulated in a object, making it difficult to post a test case) in which the column sorting breaks when the user uses the 'global' search. The columns are being filtered, but become unresponsive to sorting. Removing the global search filter restores the ordering functionality.

After digging in the code I found out that _fnDraw is being called, but it just does not create the sorted table.

Furthermore, when an individual column is being filtered, sorting keeps on working.

Any clue what could be causing this?

Replies

  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    edited October 2013
    After a lot of debugging, I narrowed down the problem to the function _fnReDraw

    [code]
    if (filter) {
    _fnFilterComplete(settings, settings.oPreviousSearch);
    }
    else {
    // No filtering, so we want to just use the display master
    settings.aiDisplay = settings.aiDisplayMaster.slice();
    }
    console.log(settings.aiDisplay, settings.aiDisplayMaster);
    [/code]

    If I use the 'global search', the order in settings.aiDisplay != the order in settings.aiDisplayMaster after sorting.

    If I use 'one column search', the order in settings.aiDisplay == the order in settings.aiDisplayMaster after sorting.
  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    edited October 2013
    Found the solution:

    When sorting, _fnFilterComplete calls _fnFilter when there is text in the global search input.

    In the _fnFilter code, it says somewhere:

    [code]
    /* Using old search array - refine it - do it this way for speed
    * Don't have to search the whole master array again
    */
    [/code]

    it seems to be some kind of 'caching' mode. In my case, this caching breaks the sorting, as _fnFilter does not consider the (sorted) aiDisplayMaster but the table as is.

    So if I force fnFilter to not use this caching (iForce = true), my problem is solved.

    Now the $1.000.000 question is: how come that I am the only one having this problem?
  • koosvdkolkkoosvdkolk Posts: 169Questions: 0Answers: 0
    Using the nightly version seems to fix this issue...
  • allanallan Posts: 63,381Questions: 1Answers: 10,449 Site admin
    Nightly as in 1.10 from git? /me crosses fingers that it is already fixed!

    Allan
This discussion has been closed.