Hi everybody, I'm not going to bore you with my life story and get straight to the point. What I'm looking to create are three dropdown's with three options for "type", "location" and "price". Which then populate "repeater1" with the results filtered from "dataset1" after choosing one or all of the options available and clicking on the "search" button. It would look something like this:
I have been working on this for a few weeks and tried so many different options and tutorials and nothing seems to work. The last one I followed was https://youtu.be/QhMKnm1f6EU because it's the closest to what I'm looking for yet when I press "search" NOTHING happens. Here's a link to what I'm working on https://www.mmcproperties.es/try4 and the code is below.
I really hope someone can help me with this before I lose my mind!
Best regards.
MB
import wixData from 'wix-data'; // For full API documentation, including code examples, visit http://wix.to/94BuAAs $w.onReady(function () { //TODO: write your page related code here... }); export function button_click(event, $w) { $w('#dataset1').setFilter(wixData.filter() .contains("type", $w('#dropdown1').value) .contains("location", $w('#dropdown2').value) .contains("price", $w('#dropdown3').value)) .then((results) => { console.log("Dataset is now filtered"); $w('#repeater1').data = results.items; }).catch((err)) = { console.log(err); }); $w('#repeater1').expand(); }
Hey MB,
Wow! I had a brain fart on this one. Completely missed that you can't use .contain for a number - and the price field is a number.
Try this:
export async function button_click(event, $w) { $w("#dataset1").setFilter(wixData.filter() .contains("type", $w('#dropdown1').value) .contains("location", $w('#dropdown2').value) .eq("price", Number($w('#dropdown3').value)) ) .then(() => { console.log("Dataset is now filtered"); }) .catch((err) => { console.log(err); }); $w('#repeater1').expand(); }
Is there a way to add a message incase of no results found? and also to search for a certain range of numbers like less than 50... ? Plz help
@Yisrael (Wix)
@givemeawhisky
here is my current code:
import wixData from 'wix-data'; export function button2_click(event, $w) { $w('#dataset1').setFilter(wixData.filter() .contains("location", $w('#haim1').value) .contains("quantity", $w('#haim2').value) .contains("reaching", $w('#haim3').value) ) .then(() => { console.log("Dataset is now filtered"); }) .catch((err) => { console.log(err); }); $w('#repeater1').expand(); } export function button3_click(event,$W) { //Add your code for this event here: $w("#dataset1").setFilter(wixData.filter()); }
Those who might need the reset button for the filter here is the code:
export function button3_click(event,$W) {
//Add your code for this event here:
$w("#dataset1").setFilter(wixData.filter());
}
I wish I could help you but I just don't know how. My code looks like this for the actual page (https://www.mmcproperties.es/properties-for-salemaybe) maybe try starting over and coping my current code for the actual page?
I also added a "-" in front of each choice (in my database and the dropdown) so you can have the option to choose "All", as well as creating what is essentially a code for myself for each item for example a
- Villa = - 1 or an - Apartment = - 3 as you can see in the example below. I also kept every value in the "field type" as "text" rather than "numbers" as it didn't work as I needed it to.
I hope this helps somewhat.
Hey,
I've also had this problem but got it working thanks to this. But after some time it just stops working and the repeater shows up empty when I'm filtering via a dropdown. I have four dropdowns and suddenly I can't just filter via ONE, I need to filter via at least two or more. Why does this happen? Have been using the exact code as above.
Thank You! MB. i don't have word how to say to thank you . thank you so much my dear friend.can we be a friend on fb. my profile is fb.com/premcharanRB Thank you.
@MB i know u did so hard work on this code and you are doing well. this is not fair to ask you but i now what you feel when some can get your reward at free. i wanted to did as u did. i tried many times do this like you. can u give me code and database creating details about above code. please give me full detail about your above filter with screenshot of database and code panel.please help me . i requested you. please.
@Yisrael (Wix) I have spent so much time working on this and was just about to give up. Thank you so very much for your prompt help!