【发布时间】:2019-07-07 00:27:13
【问题描述】:
我在我的数据表上使用自定义过滤器选择框,并尝试实现导出按钮。但是,我从选择中显示为导出标题。 我想在导出到 excel pdf 或打印时从标题中删除下拉过滤器选择值,这是我的代码,我还附上了输出的屏幕截图 我用来生成选择过滤器的代码是:
$(document).ready(function() {
$('#invoicetable').DataTable( {
dom: 'lBfrtip',
buttons: [
{ extend: 'print', filename: 'Pay Summary',title: 'Pay Summary',footer: true },
{ extend: 'excelHtml5', filename: 'Pay Summary',title: 'Pay Summary',footer: true },
{ extend: 'pdfHtml5', filename: 'Pay Summary', title: 'Pay Summary', footer: true },
],
initComplete: function () {
this.api().columns([0,2]).every( function () {
var column = this;
var select = $('<select><option value=""></option></select>')
.appendTo( $(column.header()).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>' )
} );
} );
},
"footerCallback": function ( row, data, start, end, display ) {
var totapi = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function ( i ) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '')*1 :
typeof i === 'number' ?
i : 0;
};
pageTotal = totapi
.column( 3, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
saltot = totapi
.column( 5, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
dectot = totapi
.column( 6, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
salpay = totapi
.column( 7, { page: 'current'} )
.data()
.reduce( function (a, b) {
return intVal(a) + intVal(b);
}, 0 );
// Update footer
$( totapi.column( 3 ).footer() ).html(pageTotal);
$( totapi.column( 5 ).footer() ).html(saltot);
$( totapi.column( 6 ).footer() ).html(dectot);
$( totapi.column( 7 ).footer() ).html(salpay);
}
} );
} );
【问题讨论】:
-
您需要发布Minimal, Complete, and Verifiable example,以便我们能够复制
标签: jquery datatables