Problem with SSP

Problem with SSP

artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0
edited June 14 in Free community support

Hello everyone.

cant figure out how to make it work right way.
**LInk **https://www.primoportal.de/marktanalysen/

**JS code **

! jQuery('#example').DataTable( {
! "pagingType": "numbers",
! "processing": true,
! "serverSide": true,
! "ajax": { "url" : "/wp-content/themes/dms/server_processing_marktanalysen.php",
! "data": function (d) {
! return {
! search: d.search.value,
! page: d.start,
! size: d.length
! }
! },
! dataSrc: function(data) {
! data.recordsTotal = data.totalElements;
! data.data = data.content;
! return data.data
! },
!
! },
! columns: [
! { 'data' : '1' },
! { 'data' : '2' }
! ],
! "autoWidth": false,
! "language": {"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json" }
! });
! });

Errors in concole:
Uncaught TypeError: Cannot read property 'length' of undefined jquery.dataTables.js:4126

ajax return this
http://prntscr.com/jv23k6

How should i change JS code to show fields pagination
Thanks

Replies

  • kthorngrenkthorngren Posts: 3,299Questions: 19Answers: 740
    edited June 14

    It looks like your ajax response has the correct fields according to the SSP doc. However it looks like your server script is not setup for SSP or maybe returning incorrect values due to your ajax data option. Its returning all rows (29733). Also the recordsFiltered and recordsTotal don't have the correct values. It looks like you are dropping the draw value in the request.

    {draw: 0, recordsTotal: 0, recordsFiltered: 0,…}
    data:[{1: "Baugrundstücke", 2: "Frohnau"}, {1: "Baugrundstücke", 2: "Reinickendorf"},…]
    [0 … 9999]
    [10000 … 19999]
    [20000 … 29733]
    draw:0
    recordsFiltered:0
    recordsTotal:0
    

    What are you using for your server script? Looks like it is somewhat set up to return the proper values but is not working.

    I would start by removing your ajax data option to send the request data as Datataables normally would and remove your dataSrc function as your server script seems to be responding with the correct parameters.

    If you still have issues then we probably need to look at your server script.

    Kevin

  • artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0

    @kthorngren Thanks for reply
    I changed the code to this one:

    ! jQuery('#example').DataTable( {
    ! "pagingType": "numbers",
    ! "processing": true,
    ! "serverSide": true,
    ! "ajax": { "url" : "/wp-content/themes/dms/server_processing_marktanalysen.php"},
    ! "autoWidth": false,
    ! "language": {"url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/German.json" }
    ! });
    ! });

    Now it shows first 10 rows in table, http://prntscr.com/jv89dm
    but response is still with incorrect values
    {"draw":1,"recordsTotal":0,"recordsFiltered":0,"data":[["Baugrundst\u00fccke","Frohnau"],["Baugrundst\u00fccke","Reinickendorf"],["Baugrundst\u00fccke","Spandau"],["Baugrundst\u00fccke","Mitte"],["Baugrundst\u00fccke","Mitte"],["Baugrundst\u00fccke","Unterfrank........

    Im using this serverscript https://github.com/DataTables/DataTables/blob/master/examples/server_side/scripts/ssp.class.php

  • colincolin Posts: 1,741Questions: 0Answers: 321

    Hi @artem4ik19 ,

    The recordsTotal and recordsFiltered being 0 is causing this. If you imagine the table info string, "Showing 1 to 10 of 12 entries (filtered from 57 total entries)", recordsTotal should be the total number of records (57), recordsFiltered should be the number of records that match the criteria (12).

    It would be worthwhile looking at Ajax tab on this page, that should make it more clear.

    Cheers,

    Colin

  • artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0

    @colin I understand what recordsTotal and recordsFiltered means, but problem is why server returns 0 values for them((

  • artem4ik19artem4ik19 Posts: 10Questions: 2Answers: 0

    oh, i found problem :D
    i was using ID column as $primarykey instead of ref_pk http://prntscr.com/jv9cr2

Sign In or Register to comment.