Hoping someone can access this for me cause I cannot figure it out.
The data is successfully being received, however the data won't load into the table. There's no error message. It just simply won't do it. This worked previously when I used an ajax call within the DataTable, but when I move the Ajax call outside of the DataTable creation then it does not work.
Example JSON data:
{
"data":[
{
"Id": 1,
"Name": "Fred"
},
{
"Id": 2,
"Name": "Tommy"
}
]
}
Function call to get JSON:
function getJSON() {
$.ajax({
url: "Home/GetList",
type: "GET",
datatype: "json"
}).done(function(data) {
drawDataTable('Table', data);
});
}
Drawing the DataTable
function drawDataTable(divId, data) {
var table = $('#' + divId).DataTable({
data: data,
dataSrc: "",
columnDefs: [
{ "targets": [0], "data": "Id" },
{ "targets": [1], "data": "Name" }
]
});
return table;
}
I then send this large array of data (1000 array elements) to my Datatable function via function drawDataTable(divId, data)
And within that DataTable function I use:
data: data,
dataSrc: ""
I have also tried removing the dataSrc and also making it dataSrc: "data" but neither worked.
console.logon the data parameter in thedrawDataTablefunction. Thus the data is there for the table to use.dataSrc: "data", but that's the string "data". Try instead using the actualdatavariable:dataSrc: data