how to make datatables know the total count of all data from database and send the first 10 records

how to make datatables know the total count of all data from database and send the first 10 records

mogirumemogirume Posts: 2Questions: 1Answers: 0
edited June 2022 in Free community support

Description of problem:

I have questions that are related to each other

1.) Is it possible to let datatables know, the total count of data / rows for display without querying everything?
2.) Also, is it possible to feed the first 10 records, (coming from backend api call etc.) to datatables?

Currently we're revamping the existing angularjs app that uses datatables with pagination. Currently it retrieves all the data, via api call to Laravel backend, which we intend to change to query only 10 or 20 and display it on the datatables current page. We also intend to change that clicking the page numbers should do an api call to query another 10 or 20 for display. The answers to questions above are the key to achieving this goal.

Answers

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    edited June 2022

    If you use Editor with serverside this is built-in already.
    https://datatables.net/reference/option/serverSide

  • mogirumemogirume Posts: 2Questions: 1Answers: 0
    edited June 2022

    Hello. What's Editor? could you please expand on this?

    Just to clear some things, for question #1, what I mean is, is there a way to set inside dtOptions, or something the total number of records? similar with "pageLength": 200. the goal is to make datatables know the total number of rows because it's necessary for pagination.

  • allanallan Posts: 61,653Questions: 1Answers: 10,094 Site admin

    Editor is a plug-in for DataTables to add editing. It's server-side libraries have server-side processing build in.

    What you are describing is what we call server-side processing. See here for an overview and here for details.

    1.) Is it possible to let datatables know, the total count of data / rows for display without querying everything?

    If you have that information somewhere else, then sure. For example you could have a trigger update a row count value, which is what we do in CloudTables.

    Allan

Sign In or Register to comment.