I have included select element in header of datatable. Now all the options append and show in header when I export to pdf. I do not want to show these values in header.
<script>
$(document).ready(function() {
$('#colSearch').DataTable( {
dom: 'Bfrtip',
buttons: [
{
extend: 'excel',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5, 6 ]
}
},
{
extend: 'pdf',
exportOptions: {
columns: [ 0, 1, 2, 3, 4, 5, 6 ],
},
],
initComplete: function () {
this.api().columns([0,1,2,3,4,5,6]).every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.header()))
.on( 'change', function () {
var val = $.fn.dataTable.util.escapeRegex(
$(this).val()
);
column
.search( val ? '^'+val+'$' : '', true, false )
.draw();
});
$( select ).click( function(e) {
e.stopPropagation();
});
column.data().unique().sort().each( function ( d, j ) {
var val = $('<div/>').html(d).text();
select.append( '<option value="' + val + '">' + val + '</option>' );
});
});
},
});
});
</script>
This provided solution removes all of the header. https://stackoverflow.com/a/54803204/9660462