function complete(data)
{
var bldRow=$('#Iblog').DataTable();
for(var i =0; i < data.d.results.length; i++)
{
//var rowNode =
bldRow.row.add([ data.d.results[i].Created, "<a href='#' onclick='openModal();return false;'>"+data.d.results[i].Title+"</a>", data.d.results[i].NumCommentsId]).draw();
}
//$('#myBlogData').append(bldRow);
}
function openModal() {
alert("HELLO WORLD");
}
eg:
data.d.results[i].Created
data.d.results[i].Title
data.d.results[i].NumCommentsId]
var v1,v2,v3, rv2;
for(var i =0; i < data.d.results.length; i++)
{
v1=data.d.results[i].Created;
v2=data.d.results[i].Title;
v3=data.d.results[i].NumCommentsId;
//alert(v1);
//alert(v2);
//alert(v3);
rv2= "<a href='#' onclick='openModal();return false;'>"+v2+"</a>";
bldRow.row.add([v1,rv2,v3]).draw();
}
$(document).ready(function(){
$('#blog').DataTable();
getListItems('http://www.mysite.com','Posts','complete', 'failure','timeout');
});
function getListItems(url, listname, complete, failure, timeout) {
// Executing our items via an ajax request
$.ajax({
url: url + "/_api/web/lists/getbytitle('" + listname + "')/items?select=Created,Title,NumCommentsId",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
timeout: 2000,
dataType:"json",
success: function (data) {
complete(data); // Returns JSON collection of the results
},
error: function (xhr,status,error) {
console.log(status);
}
});
function complete(data)
{
var bldRow=$('#Iblog').DataTable();
for(var i =0; i < data.d.results.length; i++)
{
//var rowNode =
bldRow.row.add([ data.d.results[i].Created, "<a href='#' onclick='openModal();return false;'>"+data.d.results[i].Title+"</a>", data.d.results[i].NumCommentsId]).draw();
}
//$('#myBlogData').append(bldRow);
}
function openModal() {
alert("open modal");
}
function failure(data) {
alert("Operation failed.");
}
}
<html>
<head>
<title></title>
<style>
table.dataTable {
width:auto !important;
}
</style>
</head>
<body>
<table id="Iblog" class="display nowrap dataTable dtr-inline" cellspacing="0">
<thead>
<tr>
<th>Date</th>
<th>Title</th>
<th># of Comments</th>
</tr>
</thead>
<!-- <tfoot>
<tr>
<th>Date</th>
<th>Title</th>
<th># of Comments</th>
<th>Category</th>
</tr>
-->
</tfoot>
<tbody id="myBlogData">
</tbody>
</table>
</body>
</html>