I am trying to filter a dataset to a collection and a price range. I have added a filter for the collection I want as well as a separate filter for the price range using a drop down but the filters are acting in a OR scenario instead of a AND scenario. I need it to remain in the same collection and find products in that price range. right now it puts in everything in the collection and all products within the price range.
But since you’re filtering based on a dropdown value, you should run the filter when the dropdown value changes.
Put it inside an onChange event handler.
Thanks for the reply J.D. I just have two more quick questions that will solve all my issues that if you can answer would be great. First question is that I am trying to filter all products in a specific collection, in this case the collection “Sofa”. I’m not sure what the right way to reference the collection is. My second question is that once I added this filter, it stopped my forEachItem function from working. If I take the filter out it works again as intended but the filter is messing with it for some reason. Why is that?
Thanks for the help in advance!
//-------------Imports-------------//
import wixData from ‘wix-data’ ; import wixLocation from ‘wix-location’ ;
//-------------Page Setup-------------//
$w.onReady( function () {
// TODO: write your page related code here…
$w( “#productImage” ).fitMode = “fit” ;
I’m not sure I got you. If you a have a field “collections” in this Products collection then filter by it using .eq (if it only contains one collection) or .contains() if it contains an array of collections (or include() if it a reference field, but then you’ll have to use the reference id).
In your case, I think it makes more sense to put the repeater.forEachItem in the .then() part of the filter as you want it to run after filtering:
$w('#dataset1').setFilter( wixData.filter()
.eq("collecions", "Sofa")
.le("price", 1000) )
.then(() => {
//put the forEach here
})
The .then statement worked perfectly! thanks for that. Unfortunately, I tried both the contains function and the include function but it still isn’t working. The picture below shows the field that I am trying to reference. It is directly out of the default products database. The issue if that since its a multi-reference field it doesn’t filter as a usual text or numerical field. Also .include only works on a query. Do you think this would be more effective as a query instead of a filter. I have noticed that filtering has long loading times.