Datatables stateSave option: “remember” search and filters

Not Laravel related, but today encountered the situation, so sharing with you. You probably know Datatables, right? It allows to quickly search and filter the table of data. But what if user then navigates away (for Edit, for example) and then wants to go back and have the same search parameters he had before? Easy.

This is not a default behavior, so, for example, if you go on Page 5, then click Edit and then hit “Back” in the browser, you will get returned to Page 1. Really inconvenient.

The cure is another parameter in Datatables called stateSave.

My simple implementation of Datatables:

Now, the only thing we need to add is this:

And as soon as you navigate back to the page (with “Back” button or even reload the page), your search filters, page and sorting will stay active.

Simple, isn’t it?

Want to generate Laravel adminpanel online?
You don't need any packages to do that!

2 thoughts on “Datatables stateSave option: “remember” search and filters

  1. Yeah datatables are the most important part in the CMS for any framework, for Laravel I’m using Yajra Datatables and it has awesome server side integration and well documented and their community is active.

Leave a Reply

Your email address will not be published. Required fields are marked *