On page TWO, I have a repeater that’s connected to a dataset filtered by user-input drop-down. On page ONE, users can click on buttons with labels of values in those dropdown filters. It takes them to page TWO and should show them the list already filtered by their click choice on the previous page. The last step isn’t working at the moment…
I’m passing the value from page ONE to TWO via session storage.
What works so far: 1. the value is stored successfully in session after clicking. 2. Users are taken to page TWO. 3. The drop down’s value is updated on page TWO correctly.
But the list on page TWO is still showing unfiltered results. I can’t figure out what I’m missing. Here is my code on page 1:
Here is my code on page 2:
Any help/pointers/hint/links is appreciated.
Thanks so much in advanced.
I’ve also tried adding on page two this code after setting the dropdown value with session to try to trigger a repeater reload, but I don’t exact know what I’m doing… sigh…
$w("#dataset1").setFilter(wixData.filter().contains("serviceSubcategory1",serviceSelection));
Tried dataset.refresh() and pulling it out of the dataset.onReady() function, but it’s not working either…
$w.onReady(function () {
const serviceSelection = session.getItem('serviceSelection');
$w('#servicedropdown').value = serviceSelection;
$w("#dataset1").refresh();
});
Figured out how to do it. My mistake was to focus on repeater when I needed to focus on the dataset, and once I include dataset filter in the code, the filter setting that I set up in the editor no longer works. I need to code the dropdown.onChange event as well.
Also I have 2 dropdown, so I needed to include multiple filter condition as well.
Here is the new code on page TWO that works for me. (page ONE’s code above works) Whoever is looking to do this and is a beginner like me, hope this is helpful for you.
**Remember to import both session and wixdata
Outside of $w.onReady()
const serviceSelection = session.getItem('serviceSelection');
const theraSelection = session.getItem('theraSelection');
Inside
$w.onReady(function () {
//If there are sessions variables for the dropdown, set it up here.
if (serviceSelection) {$w('#servicedropdown').value = serviceSelection;}
if (theraSelection){$w('#theradropdown').value = theraSelection;}
$w("#dataset1").onReady(() => {
//Filter case study dataset if sessions variables exist. There can be only one exist at any given time, service or therapeutic areas.
if (serviceSelection){
$w("#dataset1").setFilter(wixData.filter().contains("serviceSubcategory1",$w("#servicedropdown").value));
}
if (theraSelection){
$w("#dataset1").setFilter(wixData.filter().contains("therapeuticDiseaseArea1",$w("#theradropdown").value));
}
});
Then define the onChange events for the two filter dropdown:
export function servicedropdown_change(event) {
if ($w("#theradropdown").value) {
$w("#dataset1").setFilter(wixData.filter().contains("serviceSubcategory1",$w("#servicedropdown").value).contains("therapeuticDiseaseArea1",$w("#theradropdown").value));
} else {
$w("#dataset1").setFilter(wixData.filter().contains("serviceSubcategory1",$w("#servicedropdown").value));
}
}
export function theradropdown_change(event) {
if ($w("#servicedropdown").value) {
$w("#dataset1").setFilter(wixData.filter().contains("serviceSubcategory1",$w("#servicedropdown").value).contains("therapeuticDiseaseArea1",$w("#theradropdown").value));
} else {
$w("#dataset1").setFilter(wixData.filter().contains("therapeuticDiseaseArea1",$w("#theradropdown").value));
}
}
I can finally go to sleep now. Hooray!