serverSide table jumps to first page when last page items are less than pageLength

serverSide table jumps to first page when last page items are less than pageLength

AmirAMAmirAM Posts: 2Questions: 0Answers: 0

Thank you for your great Library. I'm grateful for its contributions to my projects. However, I've encountered a bug where pagination jumps to the first page when item count is less than the page length. Your attention to this issue is appreciated.

Debugger code (

Error messages shown:

There is no error in console

Description of problem:

The issue occurs when using server-side pagination in DataTables, specifically when the last page of the table has a number of items that is less than the specified page length. In this situation, upon loading the last page, the table briefly displays the remaining items but quickly triggers additional AJAX calls, causing the pagination to reset and jump back to the first page. As a result, users are unable to view the complete set of items on the last page.


draw 1 - page 1 ajax data
It made two other calls: draw 2 and 3

draw 4 - page 3 ajax data // when I click on page 3

quickly triggers additional AJAX calls -- draw 5 and 6 back to page 1

Sorry for my poor choice of words


  • kthorngrenkthorngren Posts: 20,777Questions: 26Answers: 4,857

    This example works properly when selecting the last page (page 6). The problem must be specific to your page. Sounds like there might be an event handler that that might be calling draw() or another API causing page 1 to be displayed. Please post a link to your page or a test case replicating the issue so we can help debug.


  • AmirAMAmirAM Posts: 2Questions: 0Answers: 0

    As you said, The issue was draw()

    // Listens to changes in the size of the main content element (triggered by opening or closing the sidebar),
        // and redraws the datatable to fit the new size.
        const mainContent = $(".main-content")[0];
        const resizeObserver = observeResize(mainContent, (entry) => {
Sign In or Register to comment.