Home > database >  How do I retain the values of search filter through different pages
How do I retain the values of search filter through different pages

Time:10-12

I have used search filters on one of my index view page. All the search filers are same for the second page too. I want to have a functionality in which the selected filter values from first page will be retained on the next filters too automatically and I don't have to select the filters again on the next page.

CodePudding user response:

On the index page you could add the search filters as query params to the url using jQuery.param(). On the next page you can parse and set the params as filters.

You could also store the values with localStorage. The advantage of query params is that you can easily edit, bookmark and share the url. LocalStorage is better for storing large amounts of data. See also this SO answer.

CodePudding user response:

You can use localStorage in index page to store the selected value of the filters and pass it as default value of filters in next pages

CodePudding user response:

sessionStorage.setItem('sample-filter' , filterValue);

you can use sessionStorage in first page . Because The value stored in sessionStorage will be deleted after the refresh.

after set sessionStorage you can use filter in next page :

sessionStorage.getItem('sample-filter');
  • Related