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?
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
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
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.
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
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.
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
Yeah, I was afraid you were going to say that. LOL! Thanks for your help!
You could set the
pagingType
tosimple
to just have Previous and Next buttons. There are ways to place this element anywhere on the page you like. You can use thedom
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