dynamically change filename when exporting
dynamically change filename when exporting
protome
Posts: 25Questions: 11Answers: 1
hello, i am using buttons to export my table to files. I understand I can change the name by setting "title".
Is there a way to change it dynamically, so everytime the user clicks on the button, it gets a new name ? like name+timestamp to differentiate them .
I put that in the title
thanks, pat
This discussion has been closed.
Replies
oups, my fault. I was trying to export same table without changing the data, of course the name stayed the same. Once I change the data, name changes as I say.
I post my answer in case somebody else does the same mistake! pat
Hi!
I have this problem and Im curious on how you solved it.
I want to get values from two input fields, but I only get the values which were loaded on page init.
Each of the export button types has a
filename
option which can be used to set the export file name. If you need it to be updated dynamically, that option can be given as a function that will be executed at the time of export.Allan
Hi Allan,
Thank you, how would I implement this in my above code?
Use the
filename
option . See theexcelHtml5
documentation for more information about that option.Allan
I tried to use the filename option - but it was called only once, when the document was loaded, and not when the button was pressed. Is this a bug or am I doing something wrong? By the way I couldn't see anywhere in the documentation that says it can be given as a function.
...
new $.fn.dataTable.Buttons( logTable, {
buttons: [
{
extend: 'csv',
text: 'Save Log Info',
filename: getExportFileName()
}
]
} );
...
works for me
Hmm - Thanks
I changed my example to
which indeed works, so it looks like the implementation is that there are three options
1) string - File name to give the created file
2) expression, (including a function call) - call that function to get the filename when the definition is made
3) definition of an anonymous function - execute the function when the button is pressed to get thr name of the file
Did I miss the documentation on this somewhere ?
The
csv
documentation should state that it can be a string or a function. However that appears to be missing the "type" information at the moment. I'll look into that.Allan