Returning JSON from server, No matching records found
Returning JSON from server, No matching records found
Bluestone
Posts: 9Questions: 3Answers: 0
$(document).ready(function() {
$('#hashesTable').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "../post.php",
"type": "POST",
"data": {"getValues": "1"}
},
"columns": [
{ "data": "one" },
{ "data": "two" },
{ "data": "three" },
{ "data": "four" }
]
} );
} );
http://i.imgur.com/nWa5w6B.png
Any idea what I'm missing?
Not getting any errors or anything, it just won't populate the table.
This discussion has been closed.
Replies
I managed to populate the table by adding a row.add in the success option.
Perhaps there's a better way though?
Two issues I can see:
data
should be an array of object (or an array of arrays). One item in thedata
array for each row.Allan
I added my objects to the array and there's one object on each row
http://i.imgur.com/4g1JPvK.png
Still doesn't work, just says unknown parameter '0'.
$('#subsTable').DataTable( {
serverSide: true,
ajax: {
url: '../post.php',
type: 'POST',
data: {getSubs: 1, approved: 0}
}
} );
Adding columns: [ ] back did the trick actually. I suppose there isn't a way to do this without setting the columns?
No - if you want to use objects as the data source, you have to tell DataTables. Consider for example (and keep in mind that Javascript objects are unordered) - how would DataTables know to display the "username" property in column index 0 (or whatever) if you didn't tell it? For that reason, when using objects you have to use
columns.data
to tell DataTables.Allan