简体   繁体   中英

How to remove footer on datatables print

I'm using jQuery DataTables and TableTools 2.2.4 and this is the code lines I use to initialize datatables with multi-filter inputs and the flash export buttons.

The problem is that I've been looking for the option to remove the footer of my table when user clicks on print button, because the footer is the section where are each filter input elements so I don't want to let see those inputs to customers.

I've tried to use the

'sExtends':'print','bFooter':false

but it doesn't work on print button, only with rest of the buttons it works.

tbl_consultarEmpleados is the id of my table.

And do you know how to print the table automatically. I mean, when I click on print button it sends me to a preview so I want it to send me to the direct print action like in this example .

        $(document).ready(function() 
        {
            //from here I start the datatables with multi filter options
            $('#tbl_consultarEmpleados tfoot th').each( function () {
                var title = $('#tbl_consultarEmpleados thead th').eq( $(this).index() ).text();
                $(this).html( '<input type="text" placeholder="Filtrar" />' );
            } );
            var table = $('#tbl_consultarEmpleados').DataTable();

            table.columns().every( function () {
                var that = this;

                $( 'input', this.footer() ).on( 'keyup change', function () {
                    if ( that.search() !== this.value ) {
                        that
                        .search( this.value )
                        .draw();
                    }
                } );
            } );// from here I start the flash buttoms section
        var table= $('#tbl_consultarEmpleados').dataTable();

        var tableTools = new $.fn.dataTable.TableTools(table, 
        {
            'sSwfPath': '//cdn.datatables.net/tabletools/2.2.4/swf/copy_csv_xls_pdf.swf',
            dom: 'Bfrtip',
            'aButtons': ['csv','pdf',
            {
                'sExtends':'print','bShowAll':false,'sButtonText':'Imprimir','autoPrint': true
            },

            {
                'sExtends':'xls','sFileName':'*.xls','sButtonText':'Enviar a Excel'
            },

            ],

        });

        $(tableTools.fnContainer()).insertBefore('#tbl_consultarEmpleados_wrapper')

    } );

CAUSE

According to the TableTools - Button options bFooter option affects export buttons only.

SOLUTION

With the new Buttons extension that replaced retired TableTools you can remove footer as shown below. Auto-printing is enabled by default.

$('#example').DataTable( {
    dom: 'Bfrtip',
    buttons: [
       {
           extend: 'print',
           footer: false
       }        
    ]      
} );    

See built-in print button for more information.

DEMO

See this jsFiddle for code and demonstration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM