问题
I have included dropdown to each column at footer, while generating pdf,all options are coming into header.how can we exclude these option while export?
Here is my code:
$('#example').DataTable( {
"dom": 'Bfirtlp',
buttons: [
{
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
}
},
{
extend: 'pdfHtml5',
orientation: 'landscape',
pageSize: 'A3',
exportOptions: {
columns: [ 0, 1, 2,3,4,5,6,7,8],
},
],
initComplete: function () {
this.api().columns().every( function () {
var column = this;
var eachHeader = $(column.header())[0];
var headingVal = eachHeader.getAttribute("value");
var select = $('<select class="btn btn-secondary btn-sm dropdown-toggle"><div class="dropdown-menu"><option class="dropdown-item" value="">'+ headingVal +'</option><div></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 ) {
select.append( '<option value="'+d+'">'+d+'</option>' )
} );
} );
}
} );
回答1:
I got the solutions,
include this,
exportOptions: {
format: {
header: function ( data, column, row )
{
return data.substring(data.indexOf("value")+9,data.indexOf("</option"));
}
}
},
来源:https://stackoverflow.com/questions/54787333/how-to-remove-dropdown-select-options-from-pdf-in-datatable