Difference direct function call buttons.exportData and exportOptions in initialisation

Difference direct function call buttons.exportData and exportOptions in initialisation

legamasterlegamaster Posts: 4Questions: 2Answers: 1
edited July 2016 in Free community support

Hi,
I am initialising the export buttons within the datatable initialisation:

buttons: [ 
            {
                extend: 'excelHtml5',
                text: "Excel Export",
                filename: 'Export_EKPlanung',
                footer: true,
                exportOptions: {
                    format: {
                        header: function (data, columnIdx) {
                           console.log("Data" + data);
                            return data;
                        },
                        body: function (data, columnIdx, idx) {
                            var element = table
                                .cell(idx, columnIdx)
                                .node();
                            if ($(element).children().length > 0) {
                                return $(element).children().val();
                            } else {
                                return data;
                            }

                        }
                    },
                    stripHtml: true
                }
                }
                    ]

Then the output of the console.log is e.g.:

Data<div class="DataTables_sort_wrapper">
Account<span class="DataTables_sort_icon"></span></div>

When I am using the function exportData:

table.buttons.exportData({
        format: {
            header: function (data, columnIdx) {
                console.log("data:" + data);
                return data;
            },
            body: function (data, columnIdx, idx) {
                var element = table
                    .cell(idx, columnIdx)
                    .node();
                if ($(element).children().length > 0) {
                    return $(element).children().val();
                } else {
                    return data;
                }
            },
            footer: function (data, columnIdx, idx) {
                return data;
            }

        },

    });

The console output is:

data:
Account

I am asking if this is a bug? Because I thougt exportOptions calls the function exportData. I use the 1.2.1 non-minified version.


Regards,
Denis

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,863Questions: 1Answers: 10,135 Site admin

    Hi Denis,

    It looks like you are using jQuery UI styling, so if we take this example as a base - if I run:

    $('#example').DataTable().buttons.exportData({
            format: {
                header: function (data, columnIdx) {
                    console.log("data:" + data);
                    return data;
                }
            }
    });
    

    on the console I get:

    data:<div class="DataTables_sort_wrapper">Name<span class="DataTables_sort_icon css_right ui-icon ui-icon-triangle-1-n"></span></div>
    ...
    

    The HTML has not been stripped. Indeed, it shouldn't be in your second case above. I don't understand why it wouldn't be I'm afraid.

    Do you have a page showing that problem?

    Allan

  • legamasterlegamaster Posts: 4Questions: 2Answers: 1
    edited July 2016

    Hi,

    thanks for your fast reply. Unfortunately you can't access this site outside our network unless you connect via e.g. gotomeeting.

    Edit: I deleted the bJQueryUI Option and it worked well with my first exmaple. The HTML is stripped.

    Regards,
    Denis

  • allanallan Posts: 61,863Questions: 1Answers: 10,135 Site admin
    Answer ✓

    I deleted the bJQueryUI Option

    hmm - that's interesting! I would recommend not using that option, just import the jQuery UI styling integration and it will set the appropriate defaults. That option is going to be removed in the next major version of DataTables.

    Allan

This discussion has been closed.