sorting via ajax problem

sorting via ajax problem

dgmdgm Posts: 8Questions: 0Answers: 0
edited June 2012 in DataTables 1.9
I am trying to set up a basic ajax solution, and it works for the initial data set, and when I click next it displays the next data set. This implies that my returned json must be correct.

When I click on a column header though, it shows "processing" but never updates the page. Using firebug, I have verified that a response comes back, and it does in fact show a different dataset sorted in reverse. It appears that the json returning is correct; but the table doesn't update and the "processing" never goes away.

My table and code:

[code]



Model Class
id
Updated By
Action
Created by








jQuery(function(){
var oTable = $('#audits').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "<%= audits_path %>",
"sDom": 'C<"clear">lfrtip',
"oTableTools": { },
"sPaginationType": "full_numbers",
});
});

[/code]

the JSON that is returned but ignored:

[code]
{"sEcho":1,"iTotalRecords":85329,"iTotalDisplayRecords":85329,"aaData":[["User",830,108,"create","02/01/2012 10:37 AM"],["User",724,106,"create","05/19/2011 04:39 PM"],["User",727,null,"create","05/22/2011 07:30 PM"],["User",788,null,"create","07/11/2011 07:57 PM"],["User",194,355,"destroy","03/09/2011 03:59 PM"],["User",253,355,"destroy","01/06/2011 10:39 AM"],["User",345,null,"update","02/22/2011 08:56 AM"],["User",138,138,"update","02/25/2011 11:32 PM"],["User",401,null,"update","02/16/2011 10:35 PM"],["User",933,null,"create","04/08/2012 10:34 PM"]]}
[/code]

What could be going wrong, and how can I help debug this?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    I would strongly suspect that the issue is sEcho:1 - sEcho is an internal reference for DataTables to know which draw it is performing, and it will be different for every single draw (i.e. sort, paging, filter etc). From the docs:

    [quote]
    An unaltered copy of sEcho sent from the client side. This parameter will change with each draw (it is basically a draw count) - so it is important that this is implemented. Note that it strongly recommended for security reasons that you 'cast' this parameter to an integer in order to prevent Cross Site Scripting (XSS) attacks.
    [/quote]

    ( http://datatables.net/usage/server-side )

    If it isn't that, if you could give us a link to the page, that would be really helpful in order to be able to determine what is going on.

    Thanks,
    Allan
  • dgmdgm Posts: 8Questions: 0Answers: 0
    That was it, thank you for the link to the docs... I was just guessing based on the example page, and couldn't find this page.
This discussion has been closed.