Using javascript and Jquery, I am trying to add a button for each row. I want to add a click event to button of each row. Here is my code:
reportModal = UIkit.modal("#report_modal");
$('#report_modal').empty();
var gridHtml = "<table id='table1'>"
+" <thead>"
+" <tr>"
+" <th>FirstName</th>"
+" <th>Age</th>"
+" <th>Tel</th>"
+" <th>Button</th>"
+" </tr>"
+" </thead>"
+" <tbody></tbody>"
+"</table>";
$('#report_modal').html(gridHtml);
var data = {};
data.d = [{FirstName: 'AAA', Age: '20', Tel: '111'},
{FirstName: 'BBB', Age: '98', Tel: '222'},
{FirstName: 'CCC', Age: '45', Tel: '333'}];
var trHTML = '';
for(var i = 0; i < data.d.length; i++){
trHTML += '<tr><td>' + data.d[i].FirstName + '</td><td>' + data.d[i].Age + '</td><td>' + '<a onclick="showMsg(${data.d[i].FirstName})" href="#"><i class="flaticon-icon-path"></i></a>' + '</td></tr>';
}
$('#report_modal').append(trHTML);
function showMsg(msg){
alert(msg);
}
My problem is that when click in buttons the showMsg function is called but it show "undefined";
Please any idea to solve it. Thanks.
<a onclick="showMsg(' + data.d[i].FirstName + '"