Column visibility not respected with pdf export

Column visibility not respected with pdf export

ooiooooioo Posts: 23Questions: 4Answers: 0

Hi,
when using colspan and rowspan, column visibility is not respected.
In this test case :
https://live.datatables.net/fogigafi/1
if you hide column "Position" and then click "PDF", the column Position is visible in the PDF.
Javascript :

new DataTable('#example', {
          layout: {
        topStart: {
              buttons: [{extend: 'pdfHtml5', exportOptions: {columns: ':visible'}},
        'colvis']}},
        });

Html :

<thead>
                <tr>
                    <th rowspan="2">Name</th>
                    <th colspan="2">Position and office</th>
                    <th rowspan="2">Age</th>
                    <th rowspan="2">Start date</th>
                    <th rowspan="2">Salary</th>
                </tr>
                <tr>
                    <th>Position</th>
                    <th>Office</th>
                </tr>
        </thead>

Thanks,
Pierre.

Answers

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974

    See this example for how to export only visible columns.

    Kevin

  • ooiooooioo Posts: 23Questions: 4Answers: 0

    Thank you for this link Kevin, but I export only the visible columns with exportOptions: {columns: ':visible'} and the problem seems to me related to rowspan and colspan. Am I wrong ?

    Pierre.

  • ooiooooioo Posts: 23Questions: 4Answers: 0

    In fact if the two columns regrouped in colspan (Position and Office) are hidden with colvis, then they are not visible in pdf. If just one of the two is hidden with colvis then both are visible in pdf.

    Pierre.

  • ooiooooioo Posts: 23Questions: 4Answers: 0

    It works with being explicit with columns numbers :
    exportOptions: {columns: ['0:visible', '1:visible', '2:visible', ... ]},

    Pierre.

Sign In or Register to comment.