top of page
Filter With Multiple Options

Filter With Multiple Options

Filter a repeater with multiple options using the Selection Tags element.

Intermediate.png

Intermediate

16K

Published:

February 4, 2020

Girl Enjoying her Drink

by

Anchor 1
Hire a Developer

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’.

Example Code

Tab 1

.

Tab 2

.

Tab 3

.

This code solution can be complicated.

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

  1. In $w.onReady(), run the setRepeatedItemsInRepeater() function to bind specific data to the repeater elements.

  2. Call the loadDataToRepeater() function to initially load the unfiltered recipe data into the repeater. 

  3. 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:

    1. Create a variable to hold a Wix Data query.

    2. 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.

    3. Resolve the query and set the result as the repeater’s data.

    4. If the query returns no results, show a ‘No Results Found’ text message.

APIs We Used

Non-code example.

Related Articles

Article Link

Hire a Developer

Velo solutions are powerful tools, but building them on your own can be challenging. Let an experienced Velo development shop build it for you, so you can keep working on your site or business.

Related Examples

Did this help?

Yes

|

No

Thanks for your feedback!

Featured Items

Featured Items

Feature select items on an index page.

Intermediate.png

Intermediate

Custom Store Filters

Custom Store Filters

Filter store products by name and price

Intermediate.png

Intermediate

Mega Search

Mega Search

Filter a repeater using multiple input components.

Intermediate.png

Advanced

Anchor 2
bottom of page