Data table issue. First row is Loading.. and won't sorting ?

Data table issue. First row is Loading.. and won't sorting ?

UmitCamurcukUmitCamurcuk Posts: 1Questions: 1Answers: 0
edited April 2021 in DataTables

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.

Answers

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    The ajax docs state this:

    success - Must not be overridden as it is used internally in DataTables. To manipulate / transform the data returned by the server use ajax.dataSrc (above), or use ajax as a function (below).

    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 seeing loading... as Datatables is unable to complete its loading process.

    See the ajax docs for more details. Also see the ajax examples.

    Kevin

This discussion has been closed.