Search returning zero results after using custom filtering

Search returning zero results after using custom filtering

simark95simark95 Posts: 6Questions: 3Answers: 0
edited June 2018 in Free community support
var elem,
    elems = [];

var elem2,
    elems2 = [];

    $.fn.dataTableExt.afnFiltering.push(
        function( oSettings, aData, iDataIndex ) {
            if (oSettings.nTable.id === 'order-list') {
                var elem = aData[0];
                if (elems.indexOf(elem)<0) {
                   elems[iDataIndex]=elem;
                   return true;
                } else {
                   return false;
                }     
            } else {
                var elem2 = aData[0];
                if (elems2.indexOf(elem2)<0) {
                   elems2[iDataIndex]=elem2;
                   return true;
                } else {
                   return false;
                }     
            }

        }     
    );

Above i have a filter to display only unique order IDs in the first column, sadly when i try to use the search, it returns zero results all the time. When i remove the above code, it works fine. Need help with this filter. Does it run even on a search? I want it to run only once, after initializing the table.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,176Questions: 1Answers: 2,589
    Answer ✓

    Hi @simark95 ,

    It would be worth debugging it on a live table. For example, I just tried this here, a very simplified version, and you can see that the function is called on every search and every sort. If you do something similar, with your dataset, you'll be able to debug it and see what's going on,

    Cheers,

    Colin

This discussion has been closed.