rishabh
rishabh

Reputation: 35

Browser back button doesnot save pagination history in table used from datatables

Scenario : Main Page has a link to table created from https://datatables.net/

Path followed->

  1. At main page click on table link.
  2. Table gets opened.
  3. At bottom of the table, click through several pages.
  4. Click the browser's Back button.
  5. Gone to the main page.

Intended -> Clicking Back Button should go to last seen page.

For example -

User click on page 4, then page 8, then page 7, here after clicking back button it should go to page 8

Upvotes: 0

Views: 2993

Answers (2)

JIJOMON K.A
JIJOMON K.A

Reputation: 1280

If you are using datatable , they provide a state save flag, by using that you can save your last visited page.

Code :

$(document).ready(function() {
    $('#example').DataTable( {
        stateSave: true
    } );
} );

Reference : https://datatables.net/examples/basic_init/state_save.html

Upvotes: 1

Iker Ocio Zuazo
Iker Ocio Zuazo

Reputation: 351

You should rewrite your URL with a GET parameter as http://yoururl.com/?page=3 each time that you change your table page.

Then when you come back from the browser's back button, read this parameter in order to go to your wanted page.

Edit 1: Check this to know how to manipulate your browser history: https://developer.mozilla.org/en-US/docs/Web/API/History_API#Adding_and_modifying_history_entries

Edit 2: The first that I wrote at the beginning (You should add a GET param...) it is not necessary if you modify history entries with Javascript. But I think it could be interesting in order to copy/paste URL if you want to share table content with someone.

Upvotes: 1

Related Questions