jquery - jquery datatable如何在导出到excel pdf时从标题中删除下拉过滤器选择值
问题描述
我在我的数据表上使用自定义过滤器选择框,并尝试实现导出按钮。但是,我从选择中显示为导出的标题。我想在导出到 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);
}
} );
} );
解决方案
您可以使用,
exportOptions: {
format: {
header: function ( data, column, row )
{
return data.substring(data.indexOf("value")+9,data.indexOf("</option"));
}
}
},
它为我工作
推荐阅读
- sql - 根据条件创建具有不同列的表(这是 SQL 版本)
- html - css中的半切片div三角形?使用边界半径
- linux - 权限被拒绝尝试访问 NLTK_DATA 目录时:[Errno 13]:权限被拒绝:'root/nltk_data'
- go - Go oauth2 包:err 总是 nil?
- github - 缓存实现在 github 操作中不起作用
- visual-studio - Visual Studio 2019:即使缺少内容文件,构建也会成功
- python - 如何将第一列中的值添加到新数组中?
- java - Jackson 确实包含了不应包含嵌套空值的对象
- mysql - Rust:从 mysql 读取 Polars 中的数据框
- sql - 什么是 SQL Server 2017 函数,用于分隔不同字符上的字符串,而不管长度如何