How to make exportOptions into functions ??

How to make exportOptions into functions ??

weihan123weihan123 Posts: 4Questions: 3Answers: 0
edited September 2018 in Free community support

I am trying to add a function into export functions so i can based on different parameter that i pass in, and export the columns respectively.
For example, i pass in param A, i display columns: [0, 1, 2, 3], if i pass in param B, i display column columns: [0, 1, 2]

Here is what i tried so far.

        buttons: [
            {
                extend: 'excelHtml5',
                text: 'Export',
                className: 'btn btn-success pull-right',
                init: function (api, node, config) {
                    $(node).attr("title","Export")
                    $(node).html('<i class="fa fa-file-excel-o"></i>')
                    $(node).removeClass('dt-button buttons-excel buttons-html5')
                },
                //working
                exportOptions: {
                    columns: [0, 1, 2, 3]
                },
                //not working
                exportOptions: function() {
                    columns: [0, 1, 2, 3]
                }
            }
        ],

Answers

  • kthorngrenkthorngren Posts: 21,083Questions: 26Answers: 4,908
    edited September 2018

    exportOptions: function()

    Not sure that is a supported configuration for column selection. You can try using a column-selector to get the desired columns.

    More info regarding the exportData option can be found here:
    https://datatables.net/reference/api/buttons.exportData()

    Kevin

  • weihan123weihan123 Posts: 4Questions: 3Answers: 0

    i got it work by wrapped the whole datatable instead of the exportOption, and then i pass the array data into the param and it is works now.

    var dataSet = [];
    function ShowTable(param) {
    $('#dtDetails').dataTable({
    buttons: [
    {
    extend: 'excelHtml5',
    text: 'Export',
    className: 'btn btn-success pull-right',
    init: function (api, node, config) {
    $(node).attr("title","Export")
    $(node).html('<i class="fa fa-file-excel-o"></i>')
    $(node).removeClass('dt-button buttons-excel buttons-html5')
    },
    //working
    exportOptions: {
    columns: param
    }
    }
    ],
    })
    }

    Anyway, thanks for your replied kevin.

This discussion has been closed.