๐๐ฝHello WIXer,
Do you want your users to save part of their filters on searchbars or dropdowns?
Then this is the right place for you ๐
In this tutorial, you will learn how to insert values from your filter elements into your user's Local Storage (Which can be saved for as long as possible in their browser), and then when they visit that page the values will be selected by default and so will the filter.
To accomplish this, we use the 'import { local } from 'wix-storage';' library.
I USED THE FOLLOWING APIs FOR LOCAL STORAGE๐
local.setItem("key", "value") - To save the item in local storage
local.getItem("key") - To retrieve saved item from local storage
local.removeItem("key") - To delete saved item from local storage
TO FILTER USING SAVED ITEM FROM LOCAL STORAGE ๐
In order to filter the repeater automatically, I added the wixData.query function within the $w.onReady function. This will allow the filter to run when the elements in the website are loaded.
PRETTY MUCH THAT ๐คฉ
The flow goes from the user selecting a value to filter, then the value is saved in their local browser, now when the user refreshes or revisits the same page, the value is pre-selected on their filter element and the repeater will be filtered automatically.
THANK YOU FOR READING, YOU ARE AMAZING ๐
Code
Leave a comment (0)
Thanks for leaving a comment๐