Add date to the exported filename.
Add date to the exported filename.
blockheadsilver
Posts: 12Questions: 0Answers: 0
How to add date to the filename when exporting datatables as pdf or excel ?
This discussion has been closed.
Replies
Allan
I know about that option but i have stored the date in a variable and then i want to put it into the filename...so when ever the user exports thje pdf he would get current date into the filename.
for date : var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
var d = day + "/" + month + "/" + year;
then what shall i put into sFilename : ""
Allan
The above thing sFileName=d; is not working,please help me on this...I have got the date into a variable:
for date : var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
var d = day + "/" + month + "/" + year;
Now i want to put it into my export filename along with the table name
"sDom": 'T<"H"lfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "media/swf/copy_csv_xls_pdf.swf",
"aButtons": [
"copy",
"print",
{
"sExtends": "collection",
"sButtonText": "Export",
//"mColumns": "visible",
"aButtons": [
{
"sExtends": "csv",
"sButtonText": "CSV",
"mColumns": "visible"
},
{
"sExtends": "xls",
"sButtonText": "Excel",
"mColumns": "visible"
},
{
"sExtends": "pdf",
"sButtonText": "PDF",
"sPdfOrientation": "landscape",
"sFileName": d,
"mColumns": "visible"
}]
}
]
}
I had put the sFileName:d; but it doesnt even open the pdf saving box now..nothing happens when the pdf button is clicked...please suggest me on this or if you may have some other option which can help...
Allan
Use `-` instead. This works for me:
[code]
$(document).ready( function () {
var currentDate = new Date()
var day = currentDate.getDate()
var month = currentDate.getMonth() + 1
var year = currentDate.getFullYear()
var d = day + "-" + month + "-" + year;
$('#example').dataTable( {
"sDom": 'T<"clear">lfrtip',
oTableTools: {
aButtons: [ {
sExtends: 'csv',
sFileName: d+'.csv'
} ]
}
} );
} );
[/code]
Allan
It worked...