How to initialize total records without ajax ?

How to initialize total records without ajax ?

nik75nik75 Posts: 3Questions: 1Answers: 0

Hello,

I'm really new on datatables and I have a question.
I want to initialize a datatable without ajax and use ajax for sorting and paging only.
But I don't understand how to initialize the number of total records without ajax.
I see that I have to add totalRecords attribute in the returned JSON using ajax but I don't see any param to specify this value during table init.
For example, the first page of my table contains 10 rows but I know that I have 3M results total. So how to tell to datatable to compute the number of pages based on this count ?

Do you have a solution ?

Thanks.

This question has an accepted answers - jump to answer

Answers

  • loloskiloloski Posts: 46Questions: 5Answers: 1

    if you look carefully on the documentation it will based it computation of the number of pages based on recordsTotal.

    during load time start and length will sent by datatables to your backend as GET params because it was a GET request. the documentation was clear on this.

    by default it was set this way.

    start = 0
    length = 10

    it means give me 10 rows of record then it will build the number or page based on recordsTotal value as part of the response from your server.

  • nik75nik75 Posts: 3Questions: 1Answers: 0

    Yes I understand.
    But my question is how to make the datatable build the correct number of pages during init.
    First loading of my webpage (no ajax), the table is set with HTML table that shows 10 first results for example. So the number of pages is 1 and no link to go to page 2.
    So I would like to know if I can give to the datatable the real number of elements, for example 1K so the number of pages should be 100.

  • loloskiloloski Posts: 46Questions: 5Answers: 1

    could you post to the very least of your server json response? it's hard to check without the actual data

    the attribute responsible for this is recordsTotal not totalRecords attribute as you have mentioned on your previous post

  • allanallan Posts: 63,761Questions: 1Answers: 10,510 Site admin
    Answer ✓

    If the first page of the table is initially in the HTML then you can use the deferLoading option (if you are using server-side processing - serverSide - which it sounds like you are).

    There is an example of that option in use here.

    Allan

  • nik75nik75 Posts: 3Questions: 1Answers: 0

    Thanks very much. This is exactly what I want to do.
    I have been mistaken between deferRender and deferLoading.

    Thanks for your help everybody

This discussion has been closed.