Email Data From Table
Email Data From Table
Restful Web Services
Posts: 202Questions: 49Answers: 2
in Extensions
This is just an exploratory question looking for some advice before I start trying things. I love the new buttons extension, the way you can select what data to print by column and row. I was wondering if there was any easy way to make this data from the table accessible to a form which could then be used to send the data via email.
Does anyone have any suggestions of the most practical way to go about this?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You can use the customization of print button. Grab the win.document.body html and send it to server via ajax to send it.
Or you can send the html to a hidden textarea, type email and then send. Hope it helps :)
Are there any resources which describe in detail how to send the html to a hidden textarea? That sounds like a good solution but I am not really sure how I grab the win.document.body html?
Many thanks for your help.
Is this the kind of function which would allow me to intercept the table contents so I can add it to a textarea?
Or,
Thanks
I would suggest perhaps using the Buttons
buttons.exportData()
method to get the data from the table (or justrows().data()
). It won't give you the HTML, but that is easy to create with a couple of loops if you need it for the e-mail.Then you can submit the text in an Ajax call to a server that will send the e-mail.
Allan
Hi Allan,
This sound sensible too. From a usability point of view what I think would be most sensible was if the user could press a button, Email, this would load a modal/new page which displays a form with the fields; email to, subject, notes (this would be a visible text area containing the exported table data). The user can then complete the form, amend the data in the text area if necessary, i.e. add a note or two, then press submit to send the email.
I think it is useful for the user to see the data they are emailing before it is sent rather than it going automatically.
Does this sound plausible using buttons.exportData?
Thanks
Chris
Hi Chris,
Sounds perfectly feasible. The only aspect that
buttons.exportData()
will help with is getting the data from the table - everything else you'll need to code up :-)Allan
Thanks for your help so far, I have a semi working solution but I am stuck with two things:
table.buttons.exportData
when using"columns": ':visible'
? When I enable the column visible option I cannot find a way to include the hidden columns in my data export even when I make the column 'visible' in the datatable view, i.e. by clicking the button 'column visibility' and selecting the initially hidden column.Here is what I have so far,
I dont know if this is the right way to do this but it seems to work other than the issues I have outlined above.
Is it possible to solve issue 1 or 2?
Thanks
Hi Allan,
I have solved problem one.
I want the name of the column from the header. As I am not using a table structure in my textarea I wanted to add the name of the column next to the value from the column for each row,
Thanks
Chris
I think the code needs some refinement but it is working in its current state. I looped the headers array and used a rudimentary if statement to ensure only the correct header was displayed with the correct value:
The end result is a nicely formatted entry into my forms textarea, ready for email.
Chris