Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change export PDF page size in datatables?

Tags:

pdf

datatables

My table contains more than 30 columns. I am using the datatable-JQuery and I have CSV button and PDF button for report download. I can't change page size while exporting PDF file.(When i am clicking the PDF button) . The downloaded PDF file contain half table data.

Please suggest any idea to export full table data. Thanks!

$(document).ready(function() {  
    $('#example').DataTable( {
        dom: 'Bfrtip',
        buttons: [
           {
               extend: 'csv',
               title: 'TIC TICKET REPORT',             
               exportOptions: {
               columns: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
                }
            },
           {
                extend: 'pdfHtml5',
                orientation: 'landscape',
                pageSize: 'LEGAL',
                title: 'TIC TICKET REPORT',             
                exportOptions: {
                    columns: [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]
                }
            }
        ],
        "aoColumnDefs": [{
          "bSortable": false, 
          "aTargets": []
        }],
        initComplete: function () {
            this.api().columns([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29]).every( function () {
                var column = this;
                var select = $('<select><option value="">Select</option></select>')
                    .appendTo( $(column.footer()).empty() )
                    .on( 'change', function () {

                        var val = $.fn.dataTable.util.escapeRegex(
                            $(this).val()
                        );

                        column
                            .search( val ? '^'+val+'$' : '', true, false )
                            .draw();
                    } );

                column.data().unique().sort().each( function ( d, j ) {
                    select.append( '<option value="'+d+'">'+d+'</option>' )
                } );
            } );
        }

   } );
} );  
like image 971
Ramalingam Perumal Avatar asked May 18 '16 14:05

Ramalingam Perumal


1 Answers

If you set pageSize to a string, you can use one of the following values:

'4A0', '2A0', 'A0', 'A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'A10', 'B0', 'B1', 'B2', 'B3', 'B4', 'B5', 'B6', 'B7', 'B8', 'B9', 'B10', 'C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9', 'C10', 'RA0', 'RA1', 'RA2', 'RA3', 'RA4', 'SRA0', 'SRA1', 'SRA2', 'SRA3', 'SRA4', 'EXECUTIVE', 'FOLIO', 'LEGAL', 'LETTER', 'TABLOID'

like; pageSize: 'LEGAL',

like image 163
Akf Gln Avatar answered Oct 23 '22 05:10

Akf Gln