ajax.reload() doesn't refresh paging

ajax.reload() doesn't refresh paging

sixtramsixtram Posts: 8Questions: 0Answers: 0
edited January 2021 in Free community support

I have an issue with the latest DataTables.

  • I run a search, which returns 30000 records. The correct number is shown in the status, pagination controls are there, paging works fine

  • Then I run a search, which returns only 4 records, DataTables hides the pagination controls, that is fine, too few records for pagination

  • Then I re-run the first search, which again returns 30000 records. DataTables correctly says "Showing 1 to 25 of 31,164 entries" but it doesn't display the pagination controls this time.

Each search is invoked in the following way: when hitting a submit button, I call .ajax.reload() with no parameters. This is how I construct my table:

    this._dataTable = this._table.DataTable({
        ajax: {
            method: "POST",
            url: this._model.queryUrl,
            data: (d: any) => {
                d.name = this._filter.name;
                d.email = this._filter.email;
            }
        },
        serverSide: true,
        processing: true,
        paging: true,
        pageLength: 25,
        dom: "trip"
    });

Any ideas?

Replies

  • sixtramsixtram Posts: 8Questions: 0Answers: 0

    Additional notes: I see in the DOM, that actually DataTables places the correct pagination controls into the DOM, but it doesn't remove the style dislay:none wrapper div.

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974

    Then I run a search, which returns only 4 records, DataTables hides the pagination controls, that is fine, too few records for pagination

    What are the values of the returned JSON objects recordsTotal and recordsFiltered. Would expect recordsTotal to be 31164 and recordsFiltered to be 31160. See the Server Side Docs for more details. Sounds like these values might not be correct causing the paging to disappear.

    Kevin

  • sixtramsixtram Posts: 8Questions: 0Answers: 0

    The first and third call are exactly the same and the returned json is the same as well. these are numbers after each call:

    1 - recordsTotal:31164,recordsFiltered:31164
    2- recordsTotal:4,recordsFiltered:4
    3- recordsTotal:31164,recordsFiltered:31164

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974

    I tried simulating that here:
    http://live.datatables.net/hafobala/1/edit

    But the paging element remains for each ajax.reload().

    Can you post a link to your page or a test case replicating the issue so we can debug?
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    Kevin

  • sixtramsixtram Posts: 8Questions: 0Answers: 0
    edited January 2021

    .

  • sixtramsixtram Posts: 8Questions: 0Answers: 0

    Kevin,

    That page is actually buggy I think. pageLength is 3, but it displays 4 rows for me on load, while it is saying "Showing 1 to 3 of 4 entries"

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974
    edited January 2021

    Good catch. Updated it here but it still shows the paging element:
    http://live.datatables.net/hafobala/7/edit

    Kevin

  • sixtramsixtram Posts: 8Questions: 0Answers: 0

    Kevin,

    Maybe the problem is, that my json actually returns only 25 records at a time, which is the page size, but I return recordsTotal:31164, recordsFiltered:31164.

    On the other side, when I return it the first time, it display the pagination correctly. On the third time I see that it creates the dom elements for pagination, but now it's hidden.

  • sixtramsixtram Posts: 8Questions: 0Answers: 0

    Kevin,

    One thing I've noticed, in your example the pagination controls (prev and next) are also displayed after the 2nd load, when there is only two elements.

    In that case in my application those controls are actually not there at all, it's removed when there is no need for paging.

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974

    Maybe the problem is, that my json actually returns only 25 records at a time, which is the page size, but I return recordsTotal:31164, recordsFiltered:31164.

    That is expected. Please read the Server Side Protocol Docs I linked to earlier.

    On the other side, when I return it the first time, it display the pagination correctly. On the third time I see that it creates the dom elements for pagination, but now it's hidden.

    Is there something in your code hiding the element? The Datatables elements are only created at initialization. Here it is hidden when 2 rows are displayed:
    http://live.datatables.net/vabejeme/1/edit

    Kevin

  • sixtramsixtram Posts: 8Questions: 0Answers: 0

    Kevin,

    Thanks for the hide() pointer. Made me curious, I've now searched our source code, and actually, some of our develops installed a drawCallback on

    $.extend(true, $.fn.dataTable.defaults,{})

    which in fact hides the pagination if there is only one page, but unfortunately he forgot the show it on all other cases.

    Thanks Kevin. I thought it is DataTables that hides/show the pagination, now I know it's now :)

  • kthorngrenkthorngren Posts: 21,447Questions: 26Answers: 4,974

    Great, glad you found it :smile:

    Kevin

This discussion has been closed.