How to send email with row data
How to send email with row data

Link to test case:
Debugger code (debug.datatables.net):
$('#emailLink').on('click', function (event) {
event.preventDefault();
var email = 'test@gmail.com';
var subject = 'test';
var tableHeader = ['Clip Name', 'Game ID', 'Play ID', 'Creation Time','Pre Signed URL'];
var emailBody = new Array();
$('#dataTable tbody').on('click', 'tr', function(){
var rowData = (table.row(this).data());
$.each(rowData, function(key, value) {
/*alert(tableHeader[key] + ':' + value);*/
emailBody.push(tableHeader[key] + ':' + value);
});
cosole.log(emailBody);/*returns an array*/
});
alert(emailBody);/*returns an empty array*/
window.location = 'mailto:' + email + '?subject=' + subject + '&body=' + emailBody;
});
Error messages shown: Empty array variable
Description of problem: Getting an empty array when passing to email body
Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Line 13 should give an error as
cosole
is not valid.Line 15 shows an empty array because the code in the click event, lines 7-14 wont; execute until you click a row. This click event won't be created until you click the
#emailLink
button.The Select extension would work well for this. With it you can select the rows to email and when you click the
#emailLink
button it can email to the selected rows. See this example to learn how to get the select rows. Userows().every()
with the{ selected: true }
selector-modifier
to loop through all the selected rows. This will replace lines 7-14.Kevin
Thanks for the hint. Below is the working code
And you can pass the selected row to a button or anything else using below