Need help while exporting to excel with dynamic fileName and sheetName
Need help while exporting to excel with dynamic fileName and sheetName
Hi
I have a main page on which i have a datatable, on this i have added a custom button from which i will perform a ajax call and open a pop-up using bootstrap Modal. On this pop-up i am taking fileName and sheetName from the user and there is a button to submit.
Now i am stuck i am not getting how to map the submit button click functionality directly to excel button of buttons Extension with fileName and sheetName.
I can access the datatable object on the pop-up page.
Datatable configuration are:
$.extend(true, $.fn.dataTable.defaults, {
"processing": true,
"language": {
"processing": '<span class="fa fa-refresh fa-spin" aria-hidden="true"></span> Loading Data'
},
"autoWidth": false,
"scrollX": true,
"buttons": [{
extend: 'excel',
className: 'btn-sm',
text: '<span class="glyphicon glyphicon-download-alt" aria-hidden="true"></span>',
action: function(e, dt, button, config) {
exportModule.currentDatatable = dt;
$.ajax({
url: "/exportDataTable",
type: "POST",
success: function(data) {
$("#mainpageDiv").empty().append(data);
},
error: function() {
alert("Was unable to reach export server.");
}
});
}
}],
Pop - up JS is: $('#exportButton').click(function() {
var dt = exportModule.currentDatatable;
var fileNameString = $("#filenameText").val();
var sheetNameString = $("#sheetNameText").val();
var selectedExport = getSelectedExport();
switch (selectedExport) {
case "exportXLS":
dt.button.buttons({
extend: 'excelHtml5',
filename: "fileNameString",
action: function(e, dt, node, config) {
// Do custom processing
// ...
// Call the default csvHtml5 action method to create the CSV file
$.fn.dataTable.ext.buttons.excelHtml5.action.call(this, e, dt, node, config);
}
});
}
break;
case "exportCSV":
}
});
please let me know how can i set "fileName and sheetName" in pop-up JS and call default excel function.
Answers
@allan Please help me on this