5
votes

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>' )
                } );
            } );
        }

   } );
} );  
2
You can change size when downloading, but not when exporting? What do you mean?Stephan Vierkant
While downloading PDF.(When i am clicking the PDF button)Ramalingam Perumal
Thanks for editting your question, it is now clear to me. To answer it: I don't think it's possible. A fixed width is a downside of PDF's.Stephan Vierkant

2 Answers

4
votes

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',

0
votes

Size TABLOID can adjust upto 15 columns.

 {
            extend: 'pdfHtml5',
            orientation: 'landscape',
            pageSize: 'TABLOID',
            footer: true,
}