In server-side processing can pagination be based on recordsTotal param instead of data param?

In server-side processing can pagination be based on recordsTotal param instead of data param?

jibranbjibranb Posts: 8Questions: 3Answers: 1
edited October 2018 in DataTables 1.10

I have enabled serverSide processing. I am hitting a slow-ish web service for my data, which supports paging, searching and sorting. All necessary params (start, length, search[value], etc.) are passed to and from the web service and it returns only the data for the current page.

Parameters sent

{
    draw: 1,
    start: 0,
    length: 5
    ...       
}

Parameters received

{
    data: [{},{},{},{},{}], // exactly 5 rows
    draw: 1,
    recordsFiltered: 5,
    recordsTotal: 1561
}

The issue I'm running into is pagination is based on the returned data param so there is no way to select a new page. Is it possible to display pagination buttons based on the recordsTotal param?

I hope this makes sense and isn't a stupid question.

Answers

  • jibranbjibranb Posts: 8Questions: 3Answers: 1
    edited October 2018

    I got it working. I misunderstood the definition of recordsFiltered, which is what controls pagination. Sorry to bother!

    Total records, after filtering (i.e. the total number of records after filtering has been applied - not just the number of records being returned for this page of data).

    Here are my corrected return parameters.

    {
        data: [{},{},{},{},{}], // exactly 5 rows
        draw: 1,
        recordsFiltered: 1561,
        recordsTotal: 1561
    }
    
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    No worries. Thanks for posting back and good to hear you've got it working now.

    Allan

This discussion has been closed.