How to make exportOptions into functions ??
How to make exportOptions into functions ??
weihan123
Posts: 4Questions: 3Answers: 0
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]
}
}
],
This discussion has been closed.
Answers
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
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.