How can I go to the previous page with the browser back button?

How can I go to the previous page with the browser back button?

jordonshawjordonshaw Posts: 23Questions: 9Answers: 0

I have a data table that is multiple pages. If I go to a different page than what I'm currently on, I want to be able to press the browser back button to get back to the previous page I'm was on. Currently, the URL doesn't change when you change pages in DT, so when you press the browser back button, you get the previous URL you were on, not the previous page.

A great example is the searching in this forum. If I change pages, the URL actually changes with the page #

So if you click the back button, it goes back to the previous page you were on; however, Datatables doesn't seem to work like that, unless I'm missing something?

Thanks in advance!
Jordon

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    stateSave will give you that - the state is stored in the browser so the user returns to the place they were before. See example here,

    Colin

  • jordonshawjordonshaw Posts: 23Questions: 9Answers: 0

    Thank you for your response. When I go to that example and change pages on the table, I don't have the ability to click the browser back button to go to the previous page. It doesn't seem to be working for me.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    If it's in a new tab, then there won't be any history to go back. Try changing the page in the table, or adjusting the sorting, then go to a different website, and press back from there. The table will persist with the state it was in when you left,

    Colin

  • jordonshawjordonshaw Posts: 23Questions: 9Answers: 0
    edited December 2021

    Colin,

    Thank you for your help; however, I'm not sure you fully understand what I'm trying to do. I don't want to navigate away from datatables and then come back in the same spot. I want to be on page 1 in DT, go to page 4 in DT, click the browser back button and it go back to page 1 in DT. Without ever leaving that page.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Ah I see, no, that's not possible. DataTables is JS, so it all runs within the same HTML page. The back button on the browser is to return to the previous HTML page, not states within the same page.

    Colin

  • jordonshawjordonshaw Posts: 23Questions: 9Answers: 0

    Yeah, I was afraid you were going to say that. LOL! Thanks for your help!

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951
    edited December 2021

    You could set the pagingType to simple to just have Previous and Next buttons. There are ways to place this element anywhere on the page you like. You can use the dom option to place it anywhere within the Datatatbles wrapper container. Or you can use jQuery methods to place it. somewhere else on the page.

    Maybe this Deep Linking plugin would be of interest.

    Kevin

Sign In or Register to comment.