Set page even if no exists

Set page even if no exists

personapersona Posts: 13Questions: 3Answers: 1

I need to set a page number with the api myGrid.page(pageNumber).

I saw in the code this comment:

  • Note that if you attempt to show a page which does not exist, DataTables will
  • not throw an error, but rather reset the paging.

I need to set a page number even if not exists, because I process the start elements from the server side.

Is there any way to do this?

Thanks.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin
    Answer ✓

    No sorry. As the documentation you quoted says, that is not an operation that DataTables supports. DataTables currently needs to know the total number of records and there is no option for it to go beyond that.

    Allan

  • personapersona Posts: 13Questions: 3Answers: 1

    And there is any way to overwrite this function and delete this restriction?

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    No. As I stated above, that is not an operation that DataTables supports. Sorry.

    Allan

  • personapersona Posts: 13Questions: 3Answers: 1

    The only option is destroy the table and initialize it again with displayStart option to set the page number on the first load?

    Can I change displayStart value programmatically for no destroy the table and load the grid on custom page?

  • personapersona Posts: 13Questions: 3Answers: 1

    I solved my problem destroying the table and reinitializing it with proper displayStart value.

    I think this isn't a clear solution and is a very "dirty" way to resolve my problem.

    If I set a page number (even if not exists) is my responsability check if page exists or not, datatables should not do this for me.

    If datatables is still doing this for me, then give me an API method for change the displayStart value and reload the grid without destroying all and initializing all from zero.

    Thanks.

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin
    Answer ✓

    You can set the display start using page(). However, as I stated twice above, it will not let you set a value higher than DataTables knows about for the page. If you want to change that you would have to hack DataTables (how exactly I'm not sure - it isn't something I've tried or planned for). I'm not sure how much clearer I can be about that. It is not something that DataTables supports (paging beyond the number of pages it has been told exist).

    Allan

  • personapersona Posts: 13Questions: 3Answers: 1

    Yes, I understand that datatables is not supporting this feature, but this is a requeriment that I need to implement yes or yes.

    The only ways I found to do this was:

    • Change datatables source code for not reset paging to 0 if the page number not exists (not recommended)

    • Load the table 2 times, the first time with page 0 and the next with the page I need (ugly solution, 2 request to server and 2 loads in the table)

    • Destroy table, set displayStart property and initialize it again (the best solution for me)

    The only thing I'm saying is in this case maybe would be interesting add an API method to change the displayStart property even if the page not exists (because is the functionality provided by this option at start).

    Thanks for yor replies.

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    When the table is initially created it doesn't know how many pages there are, so it can't sanity check the input, otherwise it would.

    I don't understand why you need to page past what you have told it is the number of pages? Why not just tell it the correct number of pages?

    The suggested change is not something I plan to put into DataTables core I'm afraid.

    Allan

  • personapersona Posts: 13Questions: 3Answers: 1

    I'm showing data in the table that can contains one or more pages.

    Also I'm saving the datatables state with his page number into the browser history, so if the user goes back with the navigator button, load the previous data.

    Now imagine that I receive 3 pages of data and I navigate to the third page. I save the page 3 into the browser history.

    Now the user selects other amount of data that only contains 1 page.

    If the user goes back on the navigator history, I need to load the third page of the previous data, but datatables is now with a set of data that only contains 1 page, and it's impossible load a page 3 of data if I don't destroy the table and reinitialize it with a properly displayStart.

    This is why I need to load a page that not exists in the current state of the table, but I know that I can load the page 3 because was the last data showed on the grid.

    Thanks.

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    How does the paging control know to show three pages if you only load one page of data into the table though? Are you using the serverSide option at all?

    Allan

  • personapersona Posts: 13Questions: 3Answers: 1

    Yes, I'm using serverSide option.

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    Is your server-side process returning recordsTotal and recordsFilteredto indicate the number of pages available? As I noted above I don't understand how the paging control is working at all if that isn't the case, and if it is the case, they should just be set to appropriate values to allow the page you want to change to, to be allowed.

    Allan

  • claudioxclaudiox Posts: 1Questions: 0Answers: 0
    edited February 2017

    Hi did you find any practical solution to this? I have the same problem.
    I have a table that uses serverSide:true, and added a "jump to page" field. It always jumps back to page 1 because of this

    -- EDIT -- sorry, I couldn't make it work because of draw(), solved

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    Thanks for the update. Good to hear you have it working.

This discussion has been closed.