Asp.net core 数据表中的Feltring和export

Asp.net core 数据表中的Feltring和export,asp.net-core,datatable,export-to-csv,Asp.net Core,Datatable,Export To Csv,我使用的是引导数据表 我正试图将数据表导出到excel 当我添加列筛选*(此:) $('dgv thead tr').clone(true).appendTo('dgv thead'); $('dgv thead tr:eq(0)th')。每个(函数(i){ var title=$(this.text(); $(this.html(“”); $('input',this).on('keyup change',function(){ if(table.column(i).search()!==此.

我使用的是引导数据表

我正试图将数据表导出到excel

当我添加列筛选*(此:)

$('dgv thead tr').clone(true).appendTo('dgv thead');
$('dgv thead tr:eq(0)th')。每个(函数(i){
var title=$(this.text();
$(this.html(“”);
$('input',this).on('keyup change',function(){
if(table.column(i).search()!==此.value){
桌子
.第(i)栏
.search(此.value)
.draw();
}
});
});
当我试图导出数据时,列名(标题)不显示

但是当我删除列过滤时,,列名显示正常

有什么解决办法吗

这是我的剧本:

  <script>
        $(document).ready(function () {
            // Setup - add a text input to each footer cell
            $('#dgv thead tr').clone(true).appendTo('#dgv thead');
            $('#dgv thead tr:eq(0) th').each(function (i) {
                var title = $(this).text();
                $(this).html('<input type="text" style="width:100%"  class="form-control form-control-sm" placeholder="Search ' + title + '" />');
                $('input', this).on('keyup change', function () {
                    if (table.column(i).search() !== this.value) {
                        table
                            .column(i)
                            .search(this.value)
                            .draw();
                    }
                });
            });

            var table = $('#dgv').DataTable({

                "ajax": {
                    "url": "/api/test",
                    "type": "GET",
                    "dataType": "json",
                    "dataSrc": "",


                },


            //export
            var buttons = new $.fn.dataTable.Buttons(table, {
                buttons: [
                    {

                        extend: 'copyHtml5', className: 'btn btn-outline-warning btnexport',
                        exportOptions: {
                            columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
                        }
                    },
                    {

                        extend: 'excelHtml5', className: 'btn btn-outline-warning btnexport',
                        exportOptions: {


                            columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
                        }
                    },
                    {
                        extend: 'pdfHtml5', className: 'btn btn-outline-warning btnexport',
                        orientation: 'landscape',
                        pageSize: 'LEGAL',
                        exportOptions: {

                            columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
                        }
                    }
                ]
            }).container().appendTo($('#buttons'));


        });
    </script>

$(文档).ready(函数(){
//设置-向每个页脚单元格添加文本输入
$('dgv thead tr').clone(true).appendTo('dgv thead');
$('dgv thead tr:eq(0)th')。每个(函数(i){
var title=$(this.text();
$(this.html(“”);
$('input',this).on('keyup change',function(){
if(table.column(i).search()!==此.value){
桌子
.第(i)栏
.search(此.value)
.draw();
}
});
});
变量表=$('#dgv')。数据表({
“ajax”:{
“url”:“/api/test”,
“类型”:“获取”,
“数据类型”:“json”,
“dataSrc”:“,
},
//出口
var buttons=new$.fn.dataTable.buttons(表{
按钮:[
{
扩展:“copyHtml5”,类名:“btn btn大纲警告btnexport”,
出口选择:{
列:[1,2,3,4,5,6,7,8,9,10,11,12]
}
},
{
扩展:“excelHtml5”,类名:“btn btn大纲警告btnexport”,
出口选择:{
列:[1,2,3,4,5,6,7,8,9,10,11,12]
}
},
{
扩展:“pdfHtml5”,类名:“btn btn轮廓警告btnexport”,
定位:'景观',
pageSize:'合法',
出口选择:{
列:[1,2,3,4,5,6,7,8,9,10,11,12]
}
}
]
}).container().appendTo($(“#按钮”);
});
当我试图导出数据时,列名(标题)不显示

但当我删除列筛选时,列名显示正常

您可以尝试将
$('#dgv thead tr:eq(0)th')
替换为
$('#dgv thead tr:eq(1)th')
,将过滤器输入添加到表头的第二行,如下所示

$('#dgv thead tr').clone(true).appendTo('#dgv thead');
$('#dgv thead tr:eq(1) th').each(function (i) {
    var title = $(this).text();
    $(this).html('<input type="text" style="width:100%"  class="form-control form-control-sm" placeholder="Search ' + title + '" />');
    $('input', this).on('keyup change', function () {
        if (table.column(i).search() !== this.value) {
            table
                .column(i)
                .search(this.value)
                .draw();
        }
    });
});
$('dgv thead tr').clone(true).appendTo('dgv thead');
$('dgv thead tr:eq(1)th')。每个(函数(i){
var title=$(this.text();
$(this.html(“”);
$('input',this).on('keyup change',function(){
if(table.column(i).search()!==此.value){
桌子
.第(i)栏
.search(此.value)
.draw();
}
});
});

谢谢,它成功了。但是还有其他方法可以将过滤器输入保留在第二行吗?
$('#dgv thead tr').clone(true).appendTo('#dgv thead');
$('#dgv thead tr:eq(1) th').each(function (i) {
    var title = $(this).text();
    $(this).html('<input type="text" style="width:100%"  class="form-control form-control-sm" placeholder="Search ' + title + '" />');
    $('input', this).on('keyup change', function () {
        if (table.column(i).search() !== this.value) {
            table
                .column(i)
                .search(this.value)
                .draw();
        }
    });
});