Exclude a column during excel export in Datatables

Exclude a column during excel export in Datatables

SujitJSujitJ Posts: 19Questions: 8Answers: 0

Hello

Im currently using Datatables along with child row(without ajax) and excel export. Since im using the child row logic the first column has a blank heading, hence when the export functionality (export all) is used in excel it does not include any headers in it.

$(document).ready(function() {
    var table = $('.tableContent').DataTable({
        "autoWidth": false,
        "pageLength": 50,
        dom : 'lBfrtip',
        "columnDefs" : [{
            "targets" : [ 0, 2, 3, 4, 6, 7, 9 ],
            "visible" : true,
            "searchable" : true
        }, {
            "targets" : [ 5, 8, 10 ],
            "visible" : false,
            "searchable" : false
        }, {
            "targets" : [ 1 ],
            "visible" : false,
            "searchable" : true
        }],
        buttons : [{
            extend : 'excel',
            text : 'Export to Excel',
            title : 'All Values',
            exportOptions : {
                modifier : {
                    // DataTables core
                    order : 'index', // 'current', 'applied',
                    //'index', 'original'
                    page : 'all', // 'all', 'current'
                    search : 'none' // 'none', 'applied', 'removed'
                }
            }
        }],
        "columns" : [{
            "className" : 'details-control',
            "orderable" : false
        }]
    });

    // Add event listener for opening and closing details
    $('.tableContent tbody').on('click', 'td.details-control', function () {
        var tr = $(this).closest('tr');
        var row = table.row( tr );
        var desc = table.row(this).data()[5];

        if ( row.child.isShown() ) {
            // This row is already open - close it
            row.child.hide();
            tr.removeClass('shown');
        }
        else {
            // Open this row
            row.child(format(desc)).show();
            tr.addClass('shown');
        }
    });
});

function format(d) {
    return '<table cellpadding="5" cellspacing="0" border="0" style="padding-left:50px;">'
            + '<tr>'
            + '<td>Description:</td>'
            + '<td>'
            + d
            + '</td>'
            + '</tr>'
            + '</table>';
}

How to resolve the such such that the first column (which has an image only) is excluded from the export?

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.