Pagination from Page 2 on not working

Pagination from Page 2 on not working

thebigmemphthebigmemph Posts: 2Questions: 2Answers: 0

Hi,

i'm filling my datatable with a server side processing php script.
The datatable initialize just fine, but if im changing to page 2 the data received from the server changes.

This is the data i receive on page 1:

{"draw":1,"iTotalRecords":"87","iTotalDisplayRecords":"87","aaData":[{"Feld":"id","Data":"1"},{"Feld":"Abrechnungsart","Data":"Selbstzahler"},{"Feld":"Anrede","Data":"Frau"},{"Feld":"Vorname","Data":"kkkkk"},{"Feld":"Name","Data":"bbbbbbb"},{"Feld":"Strasse","Data":"tttttttt"},{"Feld":"Stadt","Data":"11111 City"},{"Feld":"abweichende_Rechnungadresse","Data":"0"},{"Feld":"Rechnung_Empfaenger","Data":""},{"Feld":"Rechnung_Strasse","Data":""}]}

And this is the data i receive on page 2 and any further pages:

{"draw":2,"iTotalRecords":"87","iTotalDisplayRecords":"87","aaData":{"10":{"Feld":"Rechnung_Ort","Data":""},"11":{"Feld":"Geburtsdatum","Data":"2021-01-01"},"12":{"Feld":"Telefon","Data":"012345678"},"13":{"Feld":"Email","Data":"xxxxx@gggg.de"},"14":{"Feld":"Sorgeberechtigter","Data":"eeeeeeeee"},"15":{"Feld":"Sorgeberechtigter_Strasse","Data":"0"},"16":{"Feld":"Sorgeberechtigter_Stadt","Data":"0"},"17":{"Feld":"Sorgeberechtigter_Telefon","Data":"123456789"},"18":{"Feld":"Sorgeberechtigter_Mobil","Data":null},"19":{"Feld":"Sorgeberechtigter_Email","Data":null}}}

The data is built the same way, either it is page 1 or page 2:

....
$data[$columnCount]["Feld"] = $rowField;
$data[$columnCount]["Data"] = $value;
...
$response = [
   'draw' => intval($draw),
   'iTotalRecords' => $totalRecords,
   'iTotalDisplayRecords' => $totalRecordwithFilter,
        
    'aaData' => $data,
];

I don't understand why the data on page 2 and further has this leading numbers before the data.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    "aaData":{"10":{

    This is incorrect. aaData (or data if you prefer the newer notation) should be a 0 indexed array. It is in your first block, but it appears to be using the row position in the display after that, rather than just counting from 0 again.

    What is what is causing DataTables to not display the second page of data. How to fix it? That will depend upon your server-side script. It sounds like $data needs to be created a little differently from how you are doing it just now.

    Allan

Sign In or Register to comment.