0
votes

I have an API that returns some negative numbers for the Id field. Here is my datatables script:

$(document).ready(function () {
            $('#myTable').DataTable( {
                ajax: {
                    url: '@Url.Content("~/api/cas/nodes/all/lastcondition/")',
                    "columns": [
                        { "type" : "num", "data": "Id"},
                        { "data": "Name" },
                        { "data": "Alias" },
                        { "data": "DateQuery" },
                        { "type" : "num", "data": "Condition" },
                        { "type" : "num", "data": "TimeSecLastCondition" }
                    ]
                }

            } );
        });

JSON returned from ajax query:

{
    "data": [{
        "Id": -2144725655,
        "Name": "NodeName",
        "Alias": "NodeAlias",
        "DateQuery": "2015-11-13T08:16:04",
        "Condition": 0,
        "TimeSecLastCondition": 1558
    }]
}

Error:

"Requested unknown parameter '0' for row 0, column 0."

1
works fine here -> jsfiddle.net/egpxdsq7/1davidkonrad

1 Answers

3
votes

You are mixing the ajax option and other options. Instead of

ajax: {
    url: '@Url.Content("~/api/cas/nodes/all/lastcondition/")',
    "columns": [
        { "type" : "num", "data": "Id"},
        { "data": "Name" },
        { "data": "Alias" },
        { "data": "DateQuery" },
        { "type" : "num", "data": "Condition" },
        { "type" : "num", "data": "TimeSecLastCondition" }
    ]
})

you should do

ajax: {
    url: '@Url.Content("~/api/cas/nodes/all/lastcondition/")'
},
columns: [
     { "type" : "num", "data": "Id"},
     { "data": "Name" },
     { "data": "Alias" },
     { "data": "DateQuery" },
     { "type" : "num", "data": "Condition" },
     { "type" : "num", "data": "TimeSecLastCondition" }
  ]
}