Datatables Server Side processing not processing JSON output
Datatables Server Side processing not processing JSON output
arbet
Posts: 2Questions: 0Answers: 0
I am implementing Datatables with server-side processing, and I am outputting correctly formatted JSON, but for some reason datatables is not loading my data. It is stuck on the "Processing..." message. Below is my JSON string:
[quote]{
"sEcho": 0,
"iTotalRecords": 1,
"iTotalDisplayRecords": 1,
"aaData": [
[
"2011-10-27 14:32:39",
"Company added: ",
"sam",
"127.0.0.1"
]
],
"sColumns": "date,description,user,ipaddr"
}[/quote]
Is this a valid JSON? If it is, what could be the other reasons for being stuck at the "Processing..." message?
Thanks in advance for your help!
[quote]{
"sEcho": 0,
"iTotalRecords": 1,
"iTotalDisplayRecords": 1,
"aaData": [
[
"2011-10-27 14:32:39",
"Company added: ",
"sam",
"127.0.0.1"
]
],
"sColumns": "date,description,user,ipaddr"
}[/quote]
Is this a valid JSON? If it is, what could be the other reasons for being stuck at the "Processing..." message?
Thanks in advance for your help!
This discussion has been closed.
Replies
It's possible that it's not the JSON but rather another syntax error. Can you open Firebug (or other Development Tool) to the console view, and see if there are any JS errors being reported?
Could anyone point out any fields I might be missing?
My problem is that the datatable will not render the json response for server-side processing, but the EXACT same json will render correctly with server-side processing off.
I don't have a solution yet. I have made sure to have the most up to date json, jquery, and dataTables. Problem still exists.
What does your JSON return look like?
Allan
[code]
{
"sEcho": 0,
"iTotalRecords": 2,
"iTotalDisplayRecords": 2,
"aaData": [
[
"",
"551110",
"07/25/2011",
"TPA1",
"STD",
4,
"James Fulbright",
"",
"Attach"
],
[
"",
"12548",
"07/19/2011",
"TPA1",
"STD",
16,
"Wendal Lolley",
"",
"Attach"
]
]
}
[/code]
Also here is how I initialize the table:
HTML:
[code]
Claim #
Date Received
Source
Claim Type
Employee #
Employee Name
[/code]
JS:
[code]
$(document).ready(function() {
...
// claims search datatable
var claims_search_dt = $(".claims-search-table").dataTable({
"bAutoWidth": false,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": '/claims/search-claims/<?php echo $this->incident->id; ?>/',
"fnServerData": function ( sSource, aoData, fnCallback ) {
aoData = { has_select: 1 };
if ($('.claims-search-table').data("searchQuery")) {
$.extend(aoData, $('.claims-search-table').data("searchQuery"));
}
$.getJSON( sSource, aoData, function (json) { fnCallback(json); } );
},
"aoColumns": [
{ "bSortable": false },
{ "sName": "incident_number"},
{ "sName": "case_number"},
{ "sName": "employee_number"},
{ "sName": "employee_last_name"},
{ "sName": "employee_first_name"},
{ "sName": "open_date"},
{ "bSortable" : false},
{ "bSortable" : false}
],
"oLanguage": {
"sLengthMenu": "Show _MENU_",
"sProcessing": ""
},
"sDom": '<"fr"l><"table-top"r>t<"table-bottom"ip>'
});
[/code]
When bServerSide is set to true, the ajax request is made and returns the JSON above, but hangs on processing instead of rendering the table. When bServerSide is set to false, ajax request is made and returns the JSON above, but renders the table as expected.
[quote]allan said: Server-side processing requires the server to respond with more parameters that client-side processing with Ajax sourced data: http://datatables.net/usage/server-side .
What does your JSON return look like?
[/quote]
I realized that aoData was being overwritten, not extended as I intended, on Line 12 in my previous comment. None of the correct data was being sent to the server and the json response was wrong.
This may be related to the original author's problem. I noticed that the correct value for sEcho should be 1 not 0.
I was getting 0 because I was casting null to int 0 and it was null because the aoData sent to the server was not correct. The OP's JSON up above has an sEcho of 0 which I suspect is for similar reasons that mine was returning 0 as well.
So with that fixed, does it now work okay for you? The rest of your code looks fine.
Allan
I don't know why the client side do not load the data.
here is the json response
[code]
{
"sEcho": 1,
"iTotalRecords": 2,
"iTotalDisplayRecords": 2,
"aaData": [
[
"10",
"Agustin",
"Cortes",
"cargo"
],
[
"14",
"aaa",
"bbbb",
"Concejal"
]
]
}
[/code]
here is the declaration of the table
[code]
$('#Tabla').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "includes/php/tablaPersonas.php",
"iDeferLoading":2,
"aoColumns": [{ "bVisible": false},null,null,null]
}).makeEditable({
sUpdateURL: "includes/php/actualizarPersona.php",
"aoColumns": [{
onblur: 'submit'
},
{
onblur: 'submit'
},
{
tooltip: 'Cargo',
type: 'select',
onblur: 'submit',
data: "{<?php foreach ($cargos as $cargo){ ?>'<?php print($cargo->idCargo);?>':'<?php print($cargo->cargo);?>',<?php }?>}",
sUpdateURL: "includes/php/actualizarPersona.php"
}
],
sAddURL: "includes/php/agregarPersona.php",
sAddHttpMethod: "POST",
sDeleteURL: "includes/php/quitarPersona.php",
sDeleteHttpMethod: "POST",
});
[/code]
i don't know what could be the problem... any idea?
http://debug.datatables.net/alovic
Allan
0: {id:18, Name:Emkay Entertainments, Address:Nobel House, Regent Centre, Town:Lothian}
Address: "Nobel House, Regent Centre"
Name: "Emkay Entertainments"
Town: "Lothian"
id: 18
1: {id:19, Name:The Empire, Address:Milton Keynes Leisure Plaza, Town:Buckinghamshire}
2: {id:20, Name:Asadul Ltd, Address:Hophouse, Town:Essex}
3: {id:22, Name:Ashley Mark Publishing Company, Address:1-2 Vance Court, Town:Tyne & Wear}
4: {id:23, Name:MuchMoreMusic Studios, Address:Unit 29, Town:London}
5: {id:24, Name:Victoria Music Ltd, Address:Unit 215, Town:London}
6: {id:25, Name:Abacus Agent, Address:Regent Street, Town:London}
7: {id:27, Name:Pyramid Posters, Address:The Works, Town:Leicester}
8: {id:28, Name:Kingston Smith Financial Services Ltd, Address:105 St Peter's Street, Town:Herts}
9: {id:29, Name:Garrett Axford PR, Address:Harbour House, Town:West Sussex}
iTotalDisplayRecords: 93
iTotalRecords: 100
sEcho: "9"
Allan