pagination is resetting after data reload

pagination is resetting after data reload

waqqadwaqqad Posts: 7Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

This question has an accepted answers - jump to answer

Answers

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

    pagination is resetting after data reload

    You haven't provided information about your solution or what is causing the problem. I will guess you are using ajax.reload() and want to stay on the same page. See the second example in the ajax.reload() docs to see how to do this.

    If this doesn't help then please provide more details.

    Kevin

  • waqqadwaqqad Posts: 7Questions: 1Answers: 0
    edited December 18

    hello,

    i updated datatables from 1.13 to 2.1.8 version, it's working fine except when reloading data using
    table.clear().rows.add(data).draw(false);
    the pagination is reset to page 1.
    any advise?

  • waqqadwaqqad Posts: 7Questions: 1Answers: 0
    edited December 18

    hello keven,
    thanks for your prompt responce.
    i am not using ajax, i just get data through api call to google apps script from google sheets

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    It is, because when you call clear() the table rows are reduced to 0, thus paging must be reset.

    If you know you are going to be adding the same number of rows again, then store the current page start point (page()) and then set it again after you've added the new data.

    Allan

  • waqqadwaqqad Posts: 7Questions: 1Answers: 0

    hello allan,
    thanks for your answer, however it was working perfectly before upgrade, moreover the data rows might increase after every update

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

    There must have been changes in 2.x to affect the behavior of clear() and draw(). As Allan suggested use page() to get the current page before reloading the table. Then use page(), after reloading, to go to the stored page.

    Kevin

  • waqqadwaqqad Posts: 7Questions: 1Answers: 0

    var currentPage= table.page()
    console.log(currentPage)
    table.clear().rows.add(data).page(currentPage).draw(false);
    or table.clear().rows.add(data).page(currentPage).draw('page');//<<<this eleminates the data
    i did that as well kevin, but still the same issue

  • waqqadwaqqad Posts: 7Questions: 1Answers: 0

    i did it this way and now working.
    var currentPage= table.page()
    console.log(currentPage)
    table.clear().rows.add(data).draw(false);
    table.page(currentPage).draw(false);

    thanks

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    Answer ✓

    this eleminates the data

    I tried it here:
    https://live.datatables.net/kapecenu/1/edit

    You are correct. You need to call draw() for Datatables to update sorting, searching, etc with the new data. Add a draw() call after rows.add(), like this:

    table.clear().rows.add(dataSet1).draw().page( currentPage ).draw('page');
    

    You can try it in the test case.

    Kevin

  • waqqadwaqqad Posts: 7Questions: 1Answers: 0

    thanks kevin

Sign In or Register to comment.