Reputation: 2074
I get the message when trying to populate my table. Here's the simplified code.
$("#showUsers").on("click", function() {
$.ajax({
url: "/showUsers",
contentType: "application/json",
processData: false,
complete: function(data) {
$("#output").html(data.responseText);
$("#example").dataTable({
"aaData": data,
"aoColumns": [{
"sTitle": "Name",
"mDataProp": "name",
"sDefaultContent": ""
}, {
"sTitle": "Movie",
"mDataProp": "movie",
"sDefaultContent": ""
}]
});
}
});
});
And
<table id="example">
<thead>
<th>name</th>
<th>movie</th>
</thead>
</table>
The data
is assigned valid json:
[{
"name": "Dan",
"movie": "Amelie"
}, {
"name": "Rob",
"movie": "Dungeon"
}]
I've read that sometimes it messes with the table itself and the headers and stuff so I tried removing the <thead>
from my table definition but it results with the same issue.
Funny thing is that, if I replace "aaData":data
with "aaData":
plus the json itself, it works. But I can't make data
fill the requirements needed by DT.
The ajax data
comes from a node-mysql
module which is working properly.
If I change data
to data.responseText
(this is the json as shown before) I get the warning requested unknown parameter 'name' from the data source for row 0
.
I know this should be fairly simple for any not-so experienced DataTables user so thanks in advance. Somehow I'm being unable to sort it out.
The MySQL response comes with a data.responseJSON
which is a working format to give to aaData
. Thanks.
Upvotes: 3
Views: 10762
Reputation: 12000
Just got wondering why my dataTable was not filling.
In addition to the correct json format needed with aaData
, iTotalRecords
and iTotalDisplayRecord
, aaData
needs to be an array (['a', 'b', ...]
) and not an object ({'a': 'b', ...}
).
Upvotes: 0
Reputation: 2074
For the sake of flagging the question as awnsered.
SOLVED.
The mysql response comes with a data.responseJSON which is a working format to give to aaData. Thanks.
Upvotes: 1