Hello everyone, I’m new here and having some trouble with creating a dropdown menu to filter content on a dynamic gallery page. I tried to follow this tutorial Wix Code | How to Create a Search for Your Database - YouTube but somehow could not make it work (dropdown on the left), I am able to click on it but nothing appears. I also tried linking the second dropdown menu (on the right) directly with the dataset, but I can’t even click on it. Here are some screencaptures.
Thanks very much for that article! After some struggling I managed to make it work, now I have a dropdown menu showing the options for the field selected. I imagine that I’d have to do it again for each new dropdown menu, right?
Now I have two other problems:
How do I make each item selected on the dropdown menu to act as a filter, so the gallery will only show the cards that have this selected tag? This should work similarly to filtering blog posts by tag/category.
How do I create a “Show all” item that would display all items again, basically clearing up the filter?
Yes, you might need to do it for every dropdown depending on your requirements.
In order to filter your dataset, you can do it with something written like this. Add this code to run when a button is clicked or when a dropdwon changes, just as you wish…
import wixData from 'wix-data';// at the top of your page
//insert into your button/dropdown code
$w("#myDataset").setFilter( wixData.filter()
.contains("firstName", $w("#dropdown1").value
.contains("lastName", $w("#dropdown2").value
);
//
… and so forth.
To clear the filter, add the code below under the ‘clear’ button: