Server side - limited data set each Ajax call- better documentation required

Server side - limited data set each Ajax call- better documentation required

Mike ThomsonMike Thomson Posts: 9Questions: 1Answers: 0

I am using datatable for a commercial project and quite happy. I am struggling to implement server side where I want to limit returned data to (say) only 50 records at a time. The documentation touts this ability and yet the server side example uses only 57 records (datatables_demo table) and when you view xhr response all data is returned (all 57 records). Is there a better demo that shows an MySQL table being used with limit on records returned per Ajax request?

Replies

  • tangerinetangerine Posts: 3,342Questions: 35Answers: 394

    The example
    https://datatables.net/examples/data_sources/server_side.html
    is returning 10 records per call, which is the expected behaviour given a pageLength setting of 10.

  • kthorngrenkthorngren Posts: 20,139Questions: 26Answers: 4,735

    Here are the docs:
    https://datatables.net/manual/server-side

    When you looked at the xhr response did you actually see 57 data objects returned or the recordsTotal value?

    Assuming you were looking at the example Tangerine linked to you will see recordsTotal of 57 but only 10 data records.

    If the example isn't working as expected please post a link to the example and what isn't working.

    Kevin

  • Mike ThomsonMike Thomson Posts: 9Questions: 1Answers: 0

    Thanks for suggestions. I actually had an error in serverSide parameter spelling, so it was ignoring server side. I had copied demo code and installed datatables_demo database - so had it working without server side. As soon as I corrected this, I get an error 414 (Request-URI Too Large) - any suggestions?

  • allanallan Posts: 61,435Questions: 1Answers: 10,049 Site admin

    Try using POST rather than the default GET.

    Allan

  • Mike ThomsonMike Thomson Posts: 9Questions: 1Answers: 0

    Thanks Allan, Changing to Post stopped the error but whenever serverSide is set true, it displays all 57 records and ignores pageSize. (if I remove serverSide it correctly displays only 10 rows at a time). When clicking on the paging buttons I do get the "processing" message and I can see a new Ajax request (via XHR response), but each time it is for all 57 rows of data, instead of 10. I am using the PHP file server_processing.php and sspl.class.php supplied in the datatables demo (unmodified apart from connect settings (server/user/password/database) . My HTML /Javascript looks like this

    <

    script type="text/javascript">
    $(document).ready(function () {
    $('#example').DataTable({
    processing: true,
    serverSide: true,
    paging: true,
    pageSize: 10,
    ajax: {
    url:'server_processing.php',
    type: 'POST'
    }

      })
    })
    
  • allanallan Posts: 61,435Questions: 1Answers: 10,049 Site admin
    edited July 2018

    Did you update your server-side processing script to use $_POST rather than $_GET?

    Allan

  • Mike ThomsonMike Thomson Posts: 9Questions: 1Answers: 0

    Ahh, yes of course. Thanks Allan - works fine, your a champion!

This discussion has been closed.