Is there a way to email a datatable?
Is there a way to email a datatable?
mRender
Posts: 151Questions: 26Answers: 13
Possibly something like one of the table tools buttons that you click, a text box pops up and you put an e-mail address in there and hit send.
If not, what's the best way of going about emailing my tables?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Your question is not very clear.
First where are you storing the email address? You say you want to send it to datatables, but if it's only sent client side, when the user refreshes it'll be gone, since it's not stored anywhere.
Next where are you loading data from into the table? Is it getting it from an HTML table client side? Or are you using server side processing, or AJAX to load the data?
You can use jQuery to open a modal or dialog with a form input. From that form you can send the email address to your database with AJAX, then reload your table.
Since you've given no example of how your table is initialized, no live demo, or code. You should really move on to Google and search for some examples of posting forms with AJAX. Come back edit your question and show what you have tried.
It was just kind of a general question asking if there was already a way to e-mail datatables in any way. If you could help me out and point me in a general direction I'd really be appreciative of that. I've included my code below.
To try and answer your questions
You can create an HTML button and place it above your table, or next to the table tools. Or even inside with them using jQuery. The simplest thing to do is create an HTML button. Give it a unique class.
One method is with Bootstraps Modal. Clicking a button popups open a modal, which can contain a text input field and submit button where an email address is entered and submitted.
http://getbootstrap.com/javascript/#modals
Bind a jQuery event to the button, on click submit the form with AJAX to your server and process the email as needed. ie; insert it to your database. If you're not displaying the email address in the table there's no need to redraw the table.
Okay so here is my updated code with what I've been working with:
This is the code that I use to populate the e-mail button. It works and correctly calls the appropriate function.
Here is my sendemail function. The variable thehtml has the proper rows in it when I write it, but not when I e-mail it later.
Here is my code when I e-mail it:
```
$body = '
<html>
<head></head>
<body>
</html>
';
if ($headers = ""){
<?php > ``` ?>echo "error";
}
else{
echo "okay";
}
The email sends, the issue is that the e-mail doesn't have the datatable's html in it.
Use console.log(thehtml) to debug, do you see the div's html in your console debugger?
Also in sendemail.php if you echo the variable you're sending. In developer tool on the Network tab select that file after you make the AJAX request, you can then view the response and see if it's been sent correctly and received.
Alright, here's an update to what I've done to get it to work. This code e-mails the html of the datatable.
SENDEMAIL.JS
SENDEMAIL.PHP