How to put filter dropdown on top of datatable
How to put filter dropdown on top of datatable
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
change
.appendTo( $(column.footer()).empty() )
to.appendTo( $(column.header()).empty() )