PDF Export: One Column has no content

PDF Export: One Column has no content

SchmakusSchmakus Posts: 15Questions: 10Answers: 0
edited November 2015 in DataTables 1.10

Hi,

if i export my table with pdf, the third column has no content. Why?
the third column contains only digits (e.g. 0,1,2,5,...).

HTML

                <table class="table table-bordered table-hover" cellspacing="0" width="100%" id="table_show_status">
                    <thead>
                        <tr>
                            <th>Datum</th>
                            <th>Uhrzeit</th>
                            <th>Fahrzeug</th>
                            <th>Status</th>
                            <th>Dauer [h:m:s]</th>
                            <th>id</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>Datum</th>
                            <th>Uhrzeit</th>
                            <th>Fahrzeug</th>
                            <th>Status</th>
                            <th>Dauer [h:m:s]</th>
                            <th>id</th>
                        </tr>
                    </tfoot>
                </table>

Javascript

    var table_show_status = $('#table_show_status').DataTable( {
        dom:    "<'row'<'col-sm-8'l><'col-sm-2'B><'col-sm-2'f>>" +
                    "<'row'<'col-sm-12'tr>>" +
                    "<'row'<'col-sm-5'i><'col-sm-7'p>>",
        buttons: [ {
            extend: 'pdf',
            exportOptions: {
                columns: [ 0, 1, 2, 3, 4 ]
            },
            text: 'PDF erstellen',
 
            
        } ],
        "lengthMenu": [ [10, 18, 50, -1], [10, 18, 50, "All"] ],
        "ajax": {
            "url": "ajax/table.show.status.php"
        },
        "language": { "url": "js/german.js"},
        "columns": [
            { "data": "date", "orderable": false },
            { "data": "time", "orderable": false, "searchable": false },
            { "data": "fahrzeug", "orderable": true },
            { "data": "status", "orderable": false },
            { "data": "dauer", "orderable": false, "searchable": false },
            { "data": "id", "visible": false, "searchable": false },
        ],
        "order": [ [ 5, 'DESC' ] ],
        
        "columnDefs": [ 
            {
                "render": function ( data, type, row ) {
                            return data + ' Uhr';
                },
                    
                "targets": [1]
        
            }
        ],
        "rowCallback": function( row, data, index ) {
            
            switch(data['status']){
                case 0:
                    $(row).addClass('danger').css('color', '#fff')
                    break;
                case 1:
                    $(row).addClass('warning')
                    break;
                case 2:
                    $(row).addClass('success')
                    break;
                case 3:
                    $(row).addClass('info')
                    break;
                case 4:
                    $(row).addClass('primary').css('color', '#fff')
                    break;
                case 5:
                    $(row).addClass('default')
                    break;
                case 6:
                    $(row).addClass('danger').css('color', '#fff')
                    break;
            }
        },
        "initComplete": function() {
            this.api().columns().every( function () {
                var column = this;
                var select = $('<select class="form-control input-sm"><option value=""></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>' )
                } );
            });
            check_for_new_status();
        }       
    });

Answers

  • SchmakusSchmakus Posts: 15Questions: 10Answers: 0
    edited November 2015

    If I render the third column (add space bevor data), it works!
    e.g. [ ]2, [ ]3,...

                {
                    "render": function ( data, type, row ) {
                                return ' ' + data;
                    },                  
                    "targets": [3]
                }   
    
  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
    edited November 2015

    Interesting... Do you have an example of this that I can look at?

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Yup - I'd be very interested to see an example. Could you use the nightly version of Buttons if you aren't already as I've made a lot of changes in the export area.

    Allan

  • gtamentgtament Posts: 5Questions: 2Answers: 0
    edited December 2015

    I have same trouble. Another boolean column also empty. Although Schmakus' workaround works. Thanks, Schmakus.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Can you link to a test case showing the issue, using the latest version of Buttons to I can debug and correct the error in the library please.

    Allan

This discussion has been closed.