server_side example not connected to front end

server_side example not connected to front end

syn4ksyn4k Posts: 10Questions: 0Answers: 0
edited March 2011 in General
Hello all,
I have implimented the example: http://www.datatables.net/examples/server_side/server_side.html
only to discover that this example gets all data up front. even if you are paginating. This means that the pagination doesn't actually send any data to the server...so basically...the server_side example is incomplete.

In other words, let's say I have 100 records with pagination enabled and I am using the server side example.
All 100 records load and the backend queries are essentially never called because the UI for the table never sends any query parameters.

I need to know what I'm missing to make this actually send the vars to the PHP. Perhaps somebody could show us a 'working' example?

Replies

  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    If you have a look at the XHRs in Firebug for the example you linked to, you'll see that a new XHR is fired off for each page draw, and each response contains only 10 rows (or the number required for that draw) - not the full result set. Can you paste in the JSON from the example above which has the full result set from the XHR request? I don't really see how that could happen given that it is working as designed for me.

    Allan
  • syn4ksyn4k Posts: 10Questions: 0Answers: 0
    Ok, I have used the example code and here is my data:
    {"sEcho":1,"iTotalRecords":"5072","iTotalDisplayRecords":10,"aaData":[["The Robert A. Day 4 + 1 BA\/MBA Program, Claremont McKenna College","1","1","yes"],["The Robert A. Day 4 + 1 BA\/MBA Program, Claremont McKenna College","1","1","yes"],["The Robert A. Day 4 + 1 BA\/MBA Program, Claremont McKenna College","1","1","yes"],["The Robert A. Day 4 + 1 BA\/MBA Program, Claremont McKenna College","1","1","yes"],["The Robert A. Day 4 + 1 BA\/MBA Program, Claremont McKenna College","1","1","yes"],["Robert A. Day 4 Plus 1 Program, Claremont McKenna College","1","1","yes"]]}

    Note the iTotalDisplayRecords value of '10'. The records are loading into the table and the table is displaying all 5000 records....

    Ideas?
  • GregPGregP Posts: 500Questions: 10Answers: 0
    Not sure I understand. If I'm not mistaken, the iTotalRecords is correctly reporting back the total number of records that are *available* on the server side. This is necessary for pagination calculations.

    The JSON itself is only returning 10 records, for an iTotalDisplayRecords of 10.
  • syn4ksyn4k Posts: 10Questions: 0Answers: 0
    >>If I'm not mistaken, the iTotalRecords is correctly reporting back the total number of records that are *available* on the server side.
    Yes, that's correct.

    >>The JSON itself is only returning 10 records, for an iTotalDisplayRecords of 10.
    No, my json string contains 5072 records...
    The example I posted is a subset.
  • allanallan Posts: 63,400Questions: 1Answers: 10,452 Site admin
    iTotalDisplayRecords and iTotalRecords should be the same unless a filter is applied. It's trivial for DataTables to do aaData.length - so there is no need to say how many rows are in the JSON reply.

    Allan
  • syn4ksyn4k Posts: 10Questions: 0Answers: 0
    Actually they were the same but I overrode it manually because it was displaying all 5000 records...even though pagination is enabled:

    var url = "../services/getPageRecords.php";
    $('#content_table').dataTable({
    "bProcessing": true,
    "bServerSide": true,
    "bFilter":true,
    "bLengthChange": true,
    "bPaginate": true,
    "bSort": true,
    "iDisplayLength": 10,
    "sAjaxSource": url,
    "oTableTools": {
    "sSwfPath": "../plugins/datatable/copy_cvs_xls_pdf.swf"
    },
    "fnServerData": function (sSource, aoData, fnCallback)
    {
    $.ajax({
    "url": url,
    "data": data,
    "success": function(json)
    {
    fnCallback(json);
    },
    "dataType": "json",
    "cache": false,
    "error": function(xhr, error, thrown)
    {
    if (error == "parsererror")
    {
    //error(thrown);
    alert('Error ' + error);
    }
    }
    });

    },
    "sPaginationType": "full_numbers",
    "sDom": 'T<"clear">lfrtip'
    });
  • GregPGregP Posts: 500Questions: 10Answers: 0
    edited March 2011
    Sorry, I'll bow out now. ;-) Didn't understand that it was a subset you were showing. Just fired up my own application and I'm seeing an iTotalRecords of 500 and iTotalDisplayRecords of 500, yet my returned JSON only has 25 (correctly; I only want to see 25).

    If I'm understanding Allan's explanation correctly, this is the expected behaviour, so I'm at a loss for explaining why your iTotalDisplayRecords would only be 10 without filtering.
This discussion has been closed.