Skip to main content
Tutorial Free

Datatables stateSave option: "remember" search and filters

September 19, 2017
1 min read
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:
    $('#datatable').dataTable({
        "iDisplayLength": 100
    });
Now, the only thing we need to add is this:
    $('#datatable').dataTable({
        "iDisplayLength": 100,
        stateSave: true
    });
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?

Enjoyed This Tutorial?

Get access to all premium tutorials, video and text courses, and exclusive Laravel resources. Join our community of 10,000+ developers.

Recent Courses on Laravel Daily

Laravel 13 Starter Kit Teams and Customizations

10 lessons
33 min

Queues in Laravel 13

18 lessons
1 h 12 min read

How to Build Laravel 13 API From Scratch

30 lessons
1 h 23 min

No comments yet…