Data table issue. First row is Loading.. and won't sorting ?
Data table issue. First row is Loading.. and won't sorting ?
UmitCamurcuk
Posts: 1Questions: 1Answers: 0
I have a endpoint in MVC project. that endpoint returns me json data . and i wanna show that data on datatable and sort in that datatable. ı wrote my code. data table shows me the data but first row is Loading... and sorting is not work. when i click the sorting name all data is dissapears. and max. row didn't work. how can i fix it ?
$(document).ready(function () {
$('#callback_table').DataTable({
"paging":"input",
"ajax": {
"type": "GET",
"url": '/History/GetCallbackHistory',
"data": { UserId: document.getElementById("callbackuserid").value },
"dataSrc": "",
"success": function (response) {
alert("111Done!");
$.each(response, function (i, dt) {
var body = "<tr>";
body += "<td>" + dt.Id + "</td>";
body += "<td>" + dt.DateCallback + "</td>";
body += "<td>" + dt.DateEnd + "</td>";
body += "<td>" + dt.Point + "</td>";
body += "<td>" + dt.TaskId + "</td>";
body += "<td>" + typecallback[dt.callbackId] + "</td>";
body += "<td>" + dt.Task_name + "</td>";
body += "<td>" + callbackStatus[dt.callbackStatus] + "</td>";
body += "</tr>";
$("#tdata").append(body);
});
$("#callback_table").DataTable();
}
},
});
// fillTable(getData());
});
Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This discussion has been closed.
Answers
The
ajax
docs state this:Datatables will automatically load the row data. You don't need to use
success
to load the data into the table. In fact Datatbles won't know about the data you load this way and is why you are seeingloading...
as Datatables is unable to complete its loading process.See the ajax docs for more details. Also see the ajax examples.
Kevin