Ajax dataSrc as a function, with serverSide enabled, leads to no pagination

Ajax dataSrc as a function, with serverSide enabled, leads to no pagination

bbirneybbirney Posts: 3Questions: 1Answers: 0
edited May 2019 in Free community support

When using ajax.dataSrc as a function, I understand from this page that the return value of dataSrc, when used as a function, is meant to be a data array to populate the table. In this scenario, how does one also provide the recordTotal and recordsFiltered values that DataTables uses to render the pagination? I am using server-side processing, and my server application's API endpoint returns data that I need to transform with dataSrc to be consumable by DataTables. This I can do, but just handing it the array as a return value means I am getting the following for pagination:

Showing 0 to 0 of 0 entries (filtered from NaN total entries)

I tried returning an object with members 'data', 'recordsTotal', and 'recordsFiltered', but that produced no results in the data table.

Answers

  • bbirneybbirney Posts: 3Questions: 1Answers: 0

    I answered my own question. Though this isn't super clear in the documentation, the answer is to set those two properties (recordsTotal and recordsFiltered) on the input parameter (assuming it doesn't have them already). The return value of the dataSrc function isn't the only thing that's used by DataTables, apparently; it also looks at the metadata on the input object itself. If you change that to add the required properties, it will use those to produce the pagination.

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @bbirney ,

    The protocol for serverSide is discussed here in case you find other issues.

    Cheers,

    Colin

  • bbirneybbirney Posts: 3Questions: 1Answers: 0

    I added a comment to the documentation page for dataSrc explaining my resolution.

This discussion has been closed.