filter() doesn't seem to do anything

filter() doesn't seem to do anything

MWillisMWillis Posts: 10Questions: 3Answers: 0
edited July 2015 in Free community support

I'm probably missing something obvious - I have a dropdown menu that I built manually, that lives outside of the datatable. On click I trigger a filter of the datatable. I'm not getting any javascript errors, but nothing really happens. Can anyone point me in the right direction? Here's my code:

edit: I've checked the return of the .filter, and it correctly returns either true or false depending on the situation.

window.dTable = jQuery(".results").DataTable({
    "paging": false
});

jQuery(document).on("change",".filters select[name='orderStatus']", function(event){
    event.preventDefault();
    var filteredData = window.dTable
        .column( 7 )
        .data()
        .filter( function ( value, index ) {
            return jQuery(value).find("select[name='orderStatus']").val() == jQuery(".filters select[name='orderStatus']").val() ? true : false;
        }
    );
    window.dTable.draw();
});

Replies

  • allanallan Posts: 61,438Questions: 1Answers: 10,049 Site admin

    The filtered data will be available in your filteredData variable. filter() does not effect the DataTable - just the data that is available in the API instance. If you want to reduce the rows that the DataTable shows you need to use the search() method. Unfortunately, at the moment it does not accept a closure function - that is something I will be adding for 1.11.

    Allan

  • MWillisMWillis Posts: 10Questions: 3Answers: 0

    Thanks Allan, that explained it, I switched to using search instead

This discussion has been closed.