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

时间:2017-02-28 09:27:08

标签: datatables

我正在使用带有DataTable的Codeigniter和ajax请求来获取数据并尝试使用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} 
       ]
   });
}

3 个答案:

答案 0 :(得分:2)

添加此内容:

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

答案 1 :(得分: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');  

},

答案 2 :(得分:0)

添加页脚属性,如下所示

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