Example Description
In this example we used a repeater to display some recipes, and added selection tags to filter the repeater content based on multiple options selected by site visitors. For example, visitors can choose to view only recipes that are tagged as ‘Breakfast’ and ‘Dessert’.
How We Built It
Collection
We added a collection to store the recipe content. The collection has descriptive fields, as well as a ‘tags’ field of type ‘Tags’ that stores the recipe’s associated categories (Breakfast, Snack, etc.) The tags are used to filter the repeater’s content.
Page Elements
In our site we added the following page elements:
-
Repeater: To display the recipes stored in the database collection.
-
Selection tags: For visitors to choose recipe categories. Each selection tag has a value and label that correspond to a tag used in the database collection.
Code
-
In $w.onReady(), run the setRepeatedItemsInRepeater() function to bind specific data to the repeater elements.
-
Call the loadDataToRepeater() function to initially load the unfiltered recipe data into the repeater.
-
Add an onChange() event handler to the Selection Tags element. If the selection tags change, run the loadDataToRepeater() function with the selected tags as a parameter:
-
Create a variable to hold a Wix Data query.
-
Check whether any selection tags were chosen. If so, use a hasAll() filter to only get the data of collection items with all of the chosen tags.
-
Resolve the query and set the result as the repeater’s data.
-
If the query returns no results, show a ‘No Results Found’ text message.
-
Related Examples
Did this help?
|
Thanks for your feedback!
Featured Items
Feature select items on an index page.
Intermediate
Custom Store Filters
Filter store products by name and price
Intermediate
Mega Search
Filter a repeater using multiple input components.
Advanced