Hello,
I have 2 dropbox that helps me filter a dataset.
I want to filter this according to dropbox1 or dropbox1 and dropbox2.
What is the best way to do that?
top of page
Important forum update
This forum is migrating to one unified Wix community forum starting July 26th, and will be read-only during the process.
![feature fixed.png](https://static.wixstatic.com/media/3bfa8a_f845e1016b8a49758acdd6edd6610c3b~mv2.png/v1/crop/x_0,y_2,w_852,h_508/fill/w_104,h_62,al_c,q_85,usm_0.66_1.00_0.01,enc_auto/feature%20fixed.png)
Wishlist Page is the official platform for requesting new features. You can vote, comment, and track the status of the requested features.
bottom of page
@oren There are several questions similar to this in the forum.
The dataset has a filter function called setFilter(). As you will see in the documentation for this API a filter is generated using wixData.filter(). In one of the examples provided in the API documentation the basic mechanism for managing multiple filters is show...
In the above example the filter function receives two arguments, low and high. The filter function starts by creating the filter needed by the setFilter() as shown in the last line of code.
Once a filter has been created you can build on it using multiple filter options. In the example two filter options are used:
.ge: This filters using values for the selected property being greater than or equal to the value provided. In the example price being greater than or equal to low
.le: This filters using values for the selected property being less than or equal to the value provided. In the example length being less than or equal to high
The code also tests to make sure that a value for the filter exists (low or high) before setting the filter. If a value isn't provided then the filter will not be set.
Lastly unless you use the .or() filter, each filter applied in the way shown above is combined as an .and() implicitly, so you don't really need to use .and(). So they are additive and provides the effect you are looking for.
So in answer to your question you need to create a filter function that accepts the values from your drop downs as one of the parameters. The best way to accomplish this is to use the same event handler for each dropdown and then combine the results from each using the filter. So if we take the filter example above we might have a dropdown event handler for two dropdowns that is set up like this:
$w.onReady(() => { $w('#dropdown1').onChange(setDatasetFilter); $w('#dropdown2').onChange(setDatasetFilter); } function setDatasetFilter() { let low = $w('#dropdown1').value; let high = $w('#dropdown2').value; filter(low, high); }
Hope this helps.