Remove custom filtering after use $.fn.dataTable.ext.search.push

Remove custom filtering after use $.fn.dataTable.ext.search.push

DATDAT Posts: 7Questions: 3Answers: 0

Hi , i am using custom filtering to filter my rows , it works fine for me but the problem i am facing is i want to disable the filters after its use , because i have a hefty amount of data in the datatable and it gets redrawn again and again.
i am using $.fn.dataTable.ext.search.push(); for filtering . please help.

Replies

  • LaxCrosse007LaxCrosse007 Posts: 2Questions: 0Answers: 0

    So this response is late but I had the same problem and stumbled upon this post so figured I would post my answer to help anyone else who might run into this problem.

    I accomplished this by doing the following:

    -Create the function to be used for filtering as its own variable

    var myFilterFunction = FilterFunction(settings, data, dataIndex)
    

    -Add this variable to the custom filter when needed using push like usual

    $.fn.dataTable.ext.search.push(myFilterFunction)
    

    -Remove this variable from the custom filter using $.fn.dataTable.ext.search.splice(index, 1), where index is found using indexOf(variable)

    $.fn.dataTable.ext.search.splice($.fn.dataTable.ext.search.indexOf(myFilterFunction, 1));
    

    Depending on your application, you will probably want to do checks with the indexOf to make sure the function isn't already in the array before adding, and that it exists in the array before removing. Basically, check if your indexOf returns -1, and move forward appropriately.

  • allanallan Posts: 63,704Questions: 1Answers: 10,502 Site admin

    Hi,

    Thanks for posting your solution! Yes, this is currently the only way to perform this action in DataTables. I'm going to be looking into better options for the next major release.

    Allan

This discussion has been closed.