DataTable wont show server side data
DataTable wont show server side data
I am struggling with a new table implementation and I cannot figure out why lol. I've done enough of these it should just work. However when the table loads it makes the request to the server for the data but never every displays it in the table and there are NO errors in my firebug.
Here is my table instanciation code
[code]
var oTable = $('#betaCodesTable').dataTable( {
"bProcessing": true,
"bFilter": false,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "/admin/mktoolbetacodesajax/",
"oLanguage": {
"sZeroRecords": "No Beta Codes Found."
},
"aoColumnDefs": [
{"aSorting": "desc", "aTargets": [ 0 ]},
{"bVisible": false, "aTargets": [ 0 ]},
],
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "/admin-assets/TableTools.swf",
"aButtons": [
"copy", "print",
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
},
"fnServerData": function( sSource, aoData, fnCallback) {
$.getJSON(sSource, aoData, function(json) {
if(jQuery.isEmptyObject(json)) location.href = '/admin/login/';
else fnCallback(json);
});
}
} );
[/code]
and here is the server response
[code]
{
"sEcho": 0,
"iTotalRecords": "3",
"iTotalDisplayRecords": "3",
"aaData": [
[
"1",
"GDY8-88HW-XF3N-I",
"100",
"0",
"2011-12-16 00:00:00"
],
[
"2",
"EU68-5L1V-XP6Y-K",
"100",
"0",
"2011-12-15 00:00:00"
],
[
"3",
"5M69-FVCE-MQ7H-4",
"100",
"0",
"2011-12-22 00:00:00"
]
]
}
[/code]
And here is my HTML code
[code]
ID
Code
Limit
Total Redeemed
Expiration Date
Loading data from server
[/code]
Any ideas?
Here is my table instanciation code
[code]
var oTable = $('#betaCodesTable').dataTable( {
"bProcessing": true,
"bFilter": false,
"bServerSide": true,
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"sAjaxSource": "/admin/mktoolbetacodesajax/",
"oLanguage": {
"sZeroRecords": "No Beta Codes Found."
},
"aoColumnDefs": [
{"aSorting": "desc", "aTargets": [ 0 ]},
{"bVisible": false, "aTargets": [ 0 ]},
],
"sDom": '<"H"Tfr>t<"F"ip>',
"oTableTools": {
"sSwfPath": "/admin-assets/TableTools.swf",
"aButtons": [
"copy", "print",
{
"sExtends": "collection",
"sButtonText": "Save",
"aButtons": [ "csv", "xls", "pdf" ]
}
]
},
"fnServerData": function( sSource, aoData, fnCallback) {
$.getJSON(sSource, aoData, function(json) {
if(jQuery.isEmptyObject(json)) location.href = '/admin/login/';
else fnCallback(json);
});
}
} );
[/code]
and here is the server response
[code]
{
"sEcho": 0,
"iTotalRecords": "3",
"iTotalDisplayRecords": "3",
"aaData": [
[
"1",
"GDY8-88HW-XF3N-I",
"100",
"0",
"2011-12-16 00:00:00"
],
[
"2",
"EU68-5L1V-XP6Y-K",
"100",
"0",
"2011-12-15 00:00:00"
],
[
"3",
"5M69-FVCE-MQ7H-4",
"100",
"0",
"2011-12-22 00:00:00"
]
]
}
[/code]
And here is my HTML code
[code]
ID
Code
Limit
Total Redeemed
Expiration Date
Loading data from server
[/code]
Any ideas?
This discussion has been closed.
Replies
any thoughts on this allan?
With sEcho: 0 it would not work, I had to do sEcho: 1
Mental Note: Read up more on sEcho.
sEcho can never be 0 - it _must_ be the same value that DataTables sends to the server.
Allan
$sEcho = (isset($_REQUEST['sEcho')) ? $_REQUEST['sEcho'] : 0;
it appears that datatables was not sending the sEcho parameter so it was defaulting to 0, I changed it to default to 1 and it solved the issue. I am not sure why in that instance sEcho was not being sent to the server.