Remove custom filtering

Remove custom filtering

dmcleandmclean Posts: 55Questions: 2Answers: 0
edited February 2012 in General
I have a page that uses Comet to switch between two panels that use DataTables. One of them has the custom filter shown below. When I switch from the panel that uses the custom filtering to the panel that does not, this filter is causing an exception.

So what is the best way to set things up so that I can easily add and remove this filter at need?

Thanks,

Donald

[code]
/* Custom filtering function which will filter data in column four between two values */
$.fn.dataTableExt.afnFiltering.push(
function (oSettings, aData, iDataIndex) {
var selectCode = document.getElementById('statusSelect').value;
return filterRow(selectCode, aData);
}
);
[/code]

Replies

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Hi Donald,

    Unfortunately this is probably one of the biggest weak points of DataTables as it currently dads as these filters are not instance based (i.e. they apply to all tables).

    The work around is to check in your function if the table that is being operated on is the filter that you want to apply the file to. For example:

    [code]
    /* Custom filtering function which will filter data in column four between two values */
    $.fn.dataTableExt.afnFiltering.push(
    function (oSettings, aData, iDataIndex) {
    if ( oSettings.nTable.id === "my_filtering_table" ) {
    var selectCode = document.getElementById('statusSelect').value;
    return filterRow(selectCode, aData);
    }
    else {
    return true;
    }
    }
    );
    [/code]

    Making these extensions optional on an instance basis will form part of the work that will go into v1.10.

    Allan
  • dmcleandmclean Posts: 55Questions: 2Answers: 0
    Looking at my code, I started wondering if I was adding a copy of this filter every time that panel was displayed - so I moved it to a place where it should only get called once.

    Thank you for your help!

    Donald
This discussion has been closed.