Reputation: 706
I am trying to export the jQuery data tables to excel,in that i want to ask the user for the filename when Export button is clicked and download the file once filename is entered.
$('#myTable').DataTable({
buttons: [
{
extend: 'excel',
"text":'Excel <span class="glyphicon glyphicon-download-alt"></span>',
className: 'btn btn-success',
filename: 'fixed_file_name'
}
]
});
Currently if i add function for getting filename,first the file is downloaded and then the function is getting executed.like below
filename: function(){
return prompt('Please enter file name');
}
I want to call a function which prompts the user for entering the filename and once the user enters the filename it should be assigned to filename data attribute. Any help would be appreciated.
Upvotes: 3
Views: 772
Reputation: 2271
To dynamically chnage filename, refer this, which you are already referring.
But inside function, you want to prompt to enter something, and want to return that . then you can use something like below :
filename: function(){
var filename = prompt("Please enter your file name", "");
if (filename != null) {
return filename;
}
}
Edit:
looks like you had some other issue with your datatable. I also implement the same, and above solution works for me fine.
See Working Demo
Hope this will work for you.
Upvotes: 1