Is there a way to target table header using export options while exporting?

Is there a way to target table header using export options while exporting?

rprasrpras Posts: 1Questions: 1Answers: 0

I want to change the table header text when exporting. Is there a way to do this? The below example is for a col but when I use row === 0 to compare, the comparison targets table data row index 0.

var buttonCommon = {
    exportOptions: {
        format: {
            body: function ( data, row, column, node ) {
                // Strip $ from salary column to make it numeric
                return column === 5 ?
                    data.replace( /[$,]/g, '' ) :
                    data;
            }
        }
    }
};

Can someone help me with this?

Answers

  • tjdt18tjdt18 Posts: 2Questions: 0Answers: 0

    I am also looking to change the table header text when exporting. Were you able to find a way of doing that?

  • tjdt18tjdt18 Posts: 2Questions: 0Answers: 0

    Was able to resolve this issue using this post: https://datatables.net/forums/discussion/comment/111985/#Comment_111985.

    Here are the code changes:

    var buttonCommon = {
                exportOptions: {
                    format: {
                        header: function ( text, index, node ) {
                            // Change column header if it includes something
                            return text.includes("something") ?
                                text.replace( 'something', 'some other thing' ) :
                                text;
                        }
                    }
                }
            };
    

    ... and then in your buttons definitions:

    buttons: [
            $.extend( true, {}, buttonCommon, {
                    extend: 'excel'
                })
        ]
    
This discussion has been closed.