Update Select filters as per the genrated table.

Update Select filters as per the genrated table.

hhhjjjkkklllhhhjjjkkklll Posts: 7Questions: 4Answers: 0

Hi,

am using Datatables 1.10

When i select a filter in my Datatable , I am trying to update my filters as per the result set which is generated.

Here is my code.

table = $('#example').DataTable({
"bSort": false,
"fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
$("#example thead td ").each( function ( i ) {
if(i>1)
select = $('<select class="form-control"><option value=""></option></select>')
.appendTo( $(this).empty() )
.on( 'change', function () {
table.column( i )
.search( $(this).val() )
.draw();
}
);

    table.column( i ).data().unique().sort().each( function ( d, j ) {

            if(i>1&&d!==""){
                select.append( '<option value="'+d+'">'+d+'</option>' )
            }
    } );
} );

}
});

table.column( i ).data().unique().sort().each( function ( d, j );

What i am trying to do in above code is to add dropdown filter code in the callback of datatable function.

So that when each time the datatable runs i should get the new filters.

Is there any option in datatable to do this?

This discussion has been closed.