数据表打印导出选项中不包含数据表页脚

问题描述 投票:0回答:4

我正在使用 Codeigniter 和 ajax 请求与 DataTable 来获取数据,并尝试使用 DataTable 打印导出选项打印数据。但页脚没有出现在打印中。

如何在使用 DataTable 打印时包含页脚?

这是我的代码:

function data_table_report(dateselected){
    $("#dataTables-report").dataTable().fnDestroy();
    table =  $('#dataTables-report').DataTable({
        "ajax": {
        "url": "<?php echo site_url('patients_report/dataTable_report/')?>"+dateselected,
        "type": "POST",
        },
        responsive: true,
        bInfo: false,
        dom: 'Bfrtip',
        buttons: [{ extend: 'print',
            exportOptions: {
                columns: ':visible'
                 }
        },
        'colvis'],
        columnDefs: [ { 
            targets: -1,
            visible: false} 
       ]
   });
}
datatables
4个回答
2
投票

添加此:

buttons: [{ extend: 'print', footer: true }]

2
投票

添加页脚属性如下图

buttons: [{ extend: 'print',
            footer: true,
            exportOptions: {
                columns: ':visible'
                 }
         }]

1
投票

试试这个:

"fnInitComplete": function (oSettings, json) {          
    myfooter = this.find('tfoot')[0].innerHTML;
    new $.fn.dataTable.Buttons( this, {
    buttons: [          
         {
            extend: 'print',
            exportOptions : {
                columns: ':not(.notForPrint)'
            },
            customize: function ( win ) {
                $(win.document.body)
                    .css( 'font-size','10pt') 
                    .css( 'font-family','arial'); 
                $(win.document.body).find( 'table' )
                    .addClass( 'compact' )
                    .css( 'font-size', 'inherit' );
                $(win.document.body).find('tfoot')[0].innerHTML = myfooter ;
                win.print();
                setTimeout(win.close(),500);
            }
        }
    ]
    });
    this.DataTable().buttons().container().insertBefore( '#example_filter');  

},


0
投票
        "buttons" : [
            { extend: 'pdfHtml5', footer: true, exportOptions: { columns: ':visible' } },
            { extend: 'print', footer: true, exportOptions: { columns: ':visible' } },
            { extend: 'excelHtml5', footer: true, exportOptions: { columns: ':visible' } },
            ],
© www.soinside.com 2019 - 2024. All rights reserved.