I am using the DataTables Buttons for Print and CSV - how can I suppress a column

I am using the DataTables Buttons for Print and CSV - how can I suppress a column

John_HarrisJohn_Harris Posts: 2Questions: 1Answers: 0
edited February 2016 in Free community support

My DataTables view contains a column with a user-interface feature (checkbox to select a row) but I'd like this column to be suppressed in a Print or Export-to-csv view.

I've tried code like this:
'''
dataTables_searchResults.columns( '.nonPrintingColumn' ).visible( false );

dataTables_searchResults.buttons.exportData( {
        columns: ':visible'
    });

dataTables_searchResults.columns.adjust().draw( false );

and like this:
'''
var columnObj = dataTables_searchResults.column (7);

 columnObj.visible (false, true);

and then triggering the print function:

'''
$('#dataTables-buttons-holding-div div.dt-buttons a.buttons-print').click();

In some cases the column gets hidden on-screen; but it never gets hidden in the Print view or the CSV view

Here's my DataTables debug bookmarklet code: izavej

Answers

  • John_HarrisJohn_Harris Posts: 2Questions: 1Answers: 0

    I got it to work the way I wanted, using:

    '''

    var newThing = new $.fn.dataTable.Buttons(dataTables_searchResults, {
        buttons: [
            {
                extend: 'print',
                exportOptions: {
                    columns: ':visible'
                }
            },
            'csv'
        ]
    });
    

    then, in the Print triggering function:

    '''

    var columnObj = dataTables_searchResults.column (7);
    columnObj.visible (false, true);

  • allanallan Posts: 63,230Questions: 1Answers: 10,417 Site admin

    Thanks for posting back. Good to hear you've got it working.

    Allan

This discussion has been closed.