How to put filter dropdown on top of datatable

How to put filter dropdown on top of datatable

hansraj615hansraj615 Posts: 1Questions: 1Answers: 0

https://datatables.net/examples/api/multi_filter_select.html

In above link ,how to put dropdown filter on top of table

$(document).ready(function() {
$('#example2').DataTable( {
"bStateSave": true,
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.footer()).empty() )
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);

                    column
                        .search( val ? '^'+val+'$' : '', true, false )
                        .draw();
                } );

            column.data().unique().sort().each( function ( d, j ) {
if(column.search() === '^'+d+'$'){
    select.append( '<option value="'+d+'" selected="selected">'+d+'</option>' )
} else {
    select.append( '<option value="'+d+'">'+d+'</option>' )
}

} );
} );
}
} );
} );

Answers

  • Muhammad IzzatMuhammad Izzat Posts: 22Questions: 10Answers: 0
    edited September 2017

    change .appendTo( $(column.footer()).empty() ) to.appendTo( $(column.header()).empty() )

This discussion has been closed.