server side processing stuck at "processing" after ordering
server side processing stuck at "processing" after ordering
ahrboktrexon
Posts: 6Questions: 1Answers: 0
Hi guys,
I have a problem with datatable, server-side processing.
I have a lot of data, so server-side processing is needed to display them properly.
The first rendering of the datatable is ok, but when I try to change order by column I'm stuck at "processing", sever side call is done properly, data are returned, but nothing happens on the already displayed table.
This is my code, any help?
$('#tbl_orders').dataTable({
"processing": true,
"serverSide": true,
"ajax": {
"url": "ajax.php?act=Orders&method=GetOrders"
, "contentType": "application/json; charset=utf-8"
, "dataType": 'json'
, "dataSrc": function ( json ) {
json.draw = json.data.draw;
json.recordsTotal = json.data.recordsTotal;
json.recordsFiltered = json.data.recordsFiltered;
return json.data.data;
}
, "dataFilter": function(reps) {
return reps;
}, "error":function(err){
console.log(err);
}
}
, "order": [[ 1, "desc" ]]
, "columns": [
{
"data": "ch"
, 'name': 'channel'
, "render": function ( data, type, row, meta ) {
return data;
}
}
, {
"data": "dp"
, 'name': 'date_purchased'
}
, {
"data": "oId"
, 'name': 'order_id'
}
, {
"data": "sn"
, 'name': 'shipping_name'
}
, {
"data": "pr"
, 'name': 'products'
, "render": function ( data, type, row, meta ) {
return data;
}
}
, {
"data": "st"
, 'name': 'order_status'
, "render": function ( data, type, row, meta ) {
return data;
}
}
, {
"data": "sch"
, 'name': 'email_scheduled'
, "render": function ( data, type, row, meta ) {
return data;
}
}
]
, "colReorder": true
});
Thank you
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi @ahrboktrexon ,
It would normally do that when the returned JSON isn't in the expected format. The best bet is to look at the Ajax tab on this page here, and compare the return with your server side script.
Cheers,
Colin
Hi @colin,
thank you for your reply, consider that server side processing is true. I modified the server side code for simplifying degug, so only one record is returned. This is first reply
After clicking on column for ordering ajax reply is the same:
Hi @ahrboktrexon ,
If you look at the
serverSide
example here, on the Ajax tab you'll see thatdraw
,recordsTotal
are in the top level of the JSON object, and, thatdraw
value increments with every response. Both of these will give you problems. The protocol for serverSide processing is here.Cheers,
Colin
Hi @Colin,
you can see that subfields are handled by
It seems that dataTable calls dataSrc function only when table is redered for the first time.
The
ajax.dataSrc
is called each time there is an ajax request. The problem looks to be your return statement. The return statement is only returning the data but not the draw end record info. I think your code should look more like this:You might consider using a new variable so that the returned data is not doubled.
Kevin
Thank you kevin, your suggestion solved the problem... only a fix required
Thank you for your help
My reply was too soon :-( something strange is happening
this version fixes ordering of columns but breaks pagination
instead, the following code fixes first rendering and pagination but breaks ordering, stuck ad processing...
Any help?
nevermind.... my fault, everything works fine with
Thank you again for your precious help!