Data Table with SQL Table data
Data Table with SQL Table data
I'm trying to integrate jQuery Datatables to an ASP.NET project, I already searched for some help of how to fill this datatables by using an aspx method. This is what I have without success.
NT ID | ROLE |
---|
This is my table on my html file that has just a header with 3 columns and tbody is not set yet. After this I use this code to fill it
$(document).ready(function () {
//$('#MyTable').dataTable();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Security.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function (data) {
for (var i = 0; i < data.d.length; i++) {
$('#MyTable').append("<tr><td>" + data.d[i].NT_ID + "</td><td>" + data.d[i].EMAIL + "</td><td>" + data.d[i].ROLE + "</td></tr>");
}
},
error: function (result) {
alert("Error");
}
});
});
Then I try to render jQuery Datatable running this script.
$('#MyTable').dataTable({
"pagingType": "full_numbers",
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"scrollY": "400px",
"bProcessing": true,
"bServerSide": true
});
but when I run all this processes they throw me the table like this...
I dont see Search,Sorting,Pagination.
Some help is very much appreciated.
Answers
try something like
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Security.aspx/BindDatatable",
data: "{}",
dataType: "json",
success: function (data) {
$('#MyTable').dataTable({
"data":data.d,
"pagingType": "full_numbers",
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"scrollY": "400px",
"bProcessing": true,
"bServerSide": true
});
},
error: function (result) {
console.log(result);
alert("Error");
}
});
});
shoot, forgot the ''', sorry