How to attach exported excel from Datatables to email?
How to attach exported excel from Datatables to email?
rodzun
Posts: 6Questions: 4Answers: 0
I have multiple datatables for reporting purposes and I´m using the Datatables export file function (https://www.datatables.net/extensions/buttons/examples/initialisation/export.html) without any problem. Now I want to attach automatically that excel generated file into an email after I press a button or a timer goes off or something. Any ideas?
P.S. I´m using php as back-end language.
This discussion has been closed.
Answers
Im not sure you can do this easily, as its done via js, and the mail needs to be via php. Unless you get the export data (as opposed to actually forcing the download ) then send it to a php page via ajax, which sends the email
Here you go, look at the
buttons.exportData()
function, you can use that to get the exact data that the button would export, as opposed to having it create the file for download.Then use jQuery.ajax to send that content to a PHP file, which will email it.
Thanks for this, this is actually a good idea! ill implement it sometime in the next few months myself
Agreed - exactly what jLinux says is what I would suggest as well. There is no way that I know of that you could attach a created file to an e-mail client on the client-side - heck, Safari doesn't even support the methods required to download the created file...
Allan
It doesnt? Wow, how do you handle that??
Document it and make Safari fallback to Flash. If no Flash, then tough, no button.
Allan
Damn Safari. it seems like every browser has its downsides. I love chrome, but its a TERRIBLE memory hog...
I had a question about the buttons actually. I know if you use the basic buttons, all they really do is prioritize the other Flash and HTML5 buttons, does DataTables have anything that I can use to see which button was used? if any?
I ask because in My "Tool Box", you can see the
copy
,csv
,excel
andpdf
buttons are all in that one button group, and they need specific widths for that to work. So if DataTables does something like what you just said "If no Flash, then tough, no button.", how can I see that? so I know to use jQuery to alter the button group, so it wont just show a blank spot or something.Id also like to know which buttons it is, so I can change some text on the page if need be, like if the
copyFlash
doesnt work, and thecopyHtml5
is used, id like to know how to change some text that would say something specific to that.Thanks
DataTables itself doesn't, but if you right click on the button you either see a Flash context menu or not. Programmatically, I think the only option would be to check the class names of the buttons that have been added.
I see - I think the only way to know would be to execute the
available
functions yourself ($.fn.dataTable.buttons.{buttonName}.available
). Another option, possibly a better one, would be to use Flexbox to layout the buttons and it can automatically adjust the content to fit.Allan
Flexbox? as in this? If its that, it says its for:
Not sure how that can be used.
And curious why you think that would be better than using
$.fn.dataTable.buttons.{buttonName}.available
? I would think using the same methods that DT uses to manage something related to DT would be better than using a whole other 3rd party pluginCSS flexbox: http://learnlayout.com/flexbox.html .
"Better" in the sense that it should only take a couple of lines of CSS rather than needing to add and remove classes using Javascript.
Does mean only modern browsers can use it - but that might be acceptable for you.
Allan