Javascript 如果在dataTables中使用列搜索选项,则导出的PDF/EXCEL中不会显示表格标题

Javascript 如果在dataTables中使用列搜索选项,则导出的PDF/EXCEL中不会显示表格标题,javascript,jquery,pdf,datatables,Javascript,Jquery,Pdf,Datatables,我是dataTables的新用户。 我正在使用按钮导出PDF/EXCEL。这里面临一个问题。 如果使用列搜索选项,则在PDF/EXCEL中标题列不可见。 你能帮帮我吗。提前谢谢 这是我的密码: $('#exampleList thead tr#filterrow th').each( function (exampleListId) { var title = $('#exampleList thead th').eq( $(this).index() ).text(); $(this).ht

我是dataTables的新用户。 我正在使用按钮导出PDF/EXCEL。这里面临一个问题。 如果使用列搜索选项,则在PDF/EXCEL中标题列不可见。 你能帮帮我吗。提前谢谢

这是我的密码:

$('#exampleList thead tr#filterrow th').each( function (exampleListId) {
var title = $('#exampleList thead th').eq( $(this).index() ).text();

$(this).html( '<input type="text" style="width: 90%;"  id="exmpl'+exampleListId+'" placeholder="Search '+title+'"/>' ).focusout(function (e) {
    window.flagfocus=true; 
    window.searchColDets.push({
    "column": e.target.id,
    "value": e.target.value
    });             
  });       
});

$('#exampleList').DataTable({
    data: partyListArr,
    "order": [[ 2, "asc" ]],
    "pagingType": "full_numbers",
    "stateSave": true,
    "scrollY":   410,
    "scrollCollapse": true,
    "lengthMenu" : [[25, 50, 100, -1], [25, 50, 100, "All"]],
    "Filter": true,
    "destroy" : true,
    "deferRender": true,

    "sDom":'T<"toolbar">Blrtip',      
    buttons: [

            {
                extend: 'pdfHtml5',
                text: 'Save current page',
                orientation: 'landscape',
                pageSize: 'LEGAL',                  
                exportOptions: {                        
                    modifier: {
                        page: 'current'
                    },
                    columns: [ 1, 2, 3, 4, 5, 6, 7, 8, 10 ],                         
                },                 
            },
            {
                extend: 'excelHtml5',
                exportOptions: {
                    columns: [ 1, 2, 3, 4, 5, 6, 7, 8, 10 ]
                }
            },             
        ]
 }); //Close datatable
$('exampleList thead tr#filterrow th')。每个(函数(exampleListId){
var title=$('#示例列表thead th').eq($(this.index()).text();
$(this.html(“”).focusout(函数(e){
window.flagfocus=true;
window.searchs.push({
“列”:e.target.id,
“价值”:即目标价值
});             
});       
});
$('#示例列表')。数据表({
资料来源:Partylistar,
“订单”:[[2,“asc”],
“pagingType”:“完整编号”,
“国家拯救”:没错,
“卷轴”:410,
“卷轴崩溃”:没错,
“长度菜单”:[[25,50,100,-1],[25,50,100,“全部”],
“过滤器”:正确,
“毁灭”:真的,
“延迟渲染”:正确,
“sDom”:“TBlrtip”,
按钮:[
{
扩展:“pdfHtml5”,
文本:“保存当前页面”,
定位:'景观',
pageSize:'合法',
导出选项:{
修饰语:{
页面:“当前”
},
列:[1,2,3,4,5,6,7,8,10],
},                 
},
{
扩展:“excelHtml5”,
出口选择:{
列:[1,2,3,4,5,6,7,8,10]
}
},             
]
}); //关闭数据表
添加代码

<span class="hidden">' + title + '</span> 

$(this).html(
    '<span class="hidden">' + title + '</span>
    <input type="text" style="width: 90%;" id="exmpl'+exampleListId+'" placeholder="Search '+title+'"/>' 
).focusout(function (e) {
    window.flagfocus=true; 
    window.searchColDets.push({
        "column": e.target.id,
        "value": e.target.value
    });             
});
“+title+”
$(this.html)(
''+标题+'
' 
).聚焦输出(功能(e){
window.flagfocus=true;
window.searchs.push({
“列”:e.target.id,
“价值”:即目标价值
});             
});

请说明如何导出PDF,即数据表初始化代码。请检查此链接。。您好@davidkonrad,这里我添加了数据表初始化代码。现在,请您提供帮助。@neerajsimon,您的代码没有问题,它可以立即运行,只是您忘记了为xlsx downlooad->hi@davidkonrad设置适当的文件扩展名,使用此初始化,代码工作正常,但我已根据需要在标题中添加了列搜索(上面的代码),该代码以PDF/EXCEL格式显示,标题未显示。没有柱状过滤器,其工作性能极佳。但根据我的要求,我不能给列搜索在页脚。它必须仅显示在标题上。感谢您发布此问题的答案!在堆栈溢出时不鼓励只使用代码的答案,因为原始海报(或未来读者)可能很难理解它们背后的逻辑。请编辑您的答案,并包括对代码的解释,以便其他人可以从中受益。谢谢