Hussein Zaki
Hussein Zaki

Reputation: 19

Datatables Filter dropmenu

i Want to filter Datatables using this line data: ["Accepted", "Delivered", "Pending", "Cancel"], filter_default_label: "Select Status" but the data which will be filter is already in drop-menu [enter image description here][1] like here in the image the drop-menu show pending so if there was other word like cancel okay i want to filter all the rows on the table which show pending not cancel in the table

Upvotes: 1

Views: 444

Answers (1)

Daniel
Daniel

Reputation: 37061

So basically your column should use the custom_func, see complete column setup below:

{    
    column_number : 2, 
    data: ["Accepted", "Delivered", "Pending", "Cancel"], filter_default_label: "Select Status", 
    filter_type: 'custom_func', 
    custom_func: myCustomFilterFunction
},

where myCustomFilterFunction should look like this:

 function myCustomFilterFunction(filterVal, columnVal) {
        var found;
        if (columnVal === '') {
            return true;
        }
        if ($(columnVal).val() === filterVal) {
            return true;
        }
        return false;
 }

But in order for that to work you must update each select when its being changed (its html/datatbles data) should be updated after each change - otherwise the old value will remain as selected in the table and yadcf wont be able to tell its updated value

see following test page

Upvotes: 1

Related Questions