Hello,
I created this page to show a list of items on repeater (connected to a database). I have a dropdown menu that filters the repeater, but I also have an “All” option on the dropdown to show everything again.
How do you display all items when “All” is selected on the menu?
Any help is much appreciated.
What you do is use an empty filter.
$w(‘#dataset1’).setFilter(wixData.filter());
“To clear a dataset’s current filter, call setFilter() and pass it an empty filter. You create an empty filter by calling the filter() function without chaining any of the additional filter functions “
Thank you! I’m trying to call the empty filter when “All” is selected on the dropdown menu. So currently, I have this but when “All” is selected, there is no change. Can you help me figure out what’s wrong?
export function typeDropdown_change(event){
let filterType = $w(‘#typeDropdown’).value;
if (filterType === “All”){
$w(‘#dataset1’).setFilter(wixData.filter().contains());
} else {
$w(‘#dataset1’).setFilter(wixData.filter().contains(“type”, filterType));
}
}
Hey @anezkachua
like this
export function typeDropdown_change(event){
let filterType = $w('#typeDropdown').value;
if (filterType === "All"){
$w('#dataset1').setFilter(wixData.filter());
} else{
$w('#dataset1').setFilter(wixData.filter().contains("type", filterType));
}
}
@anezkachua As I said you need to use an empty filter. You have added a .contains() to the empty filter so it is no longer empty :-).
Remove .contains().
@salman-hammed Basically you are right but the element naming you have proposed is a little strange for example $w(‘#dataset1’#dataset1’) should be $w(‘#dataset1’).
@stevendc Hey I try to change but it’s wierd on edit mode it shows #dataset1 when i click publish it shows #dataset1#dataset1
Here’s the screenshot
@salman-hammed That is a bit weird. Can you share the url of the page you are referring to?
@stevendc
This same URL check my comments above?
The bug is in Wix forum not in Wix sites
@salman-hammed A test
export function typeDropdown_change(event){
let filterType = $w('#typeDropdown').value;
if (filterType === "All"){
$w('#dataset1').setFilter(wixData.filter());
} else{
$w('#dataset1').setFilter(wixData.filter().contains("type", filterType));
}
}
Seems odd
Well it’s work on this comment’s though
Do you want me to take a video screenshots?
@salman-hammed Ok no problem. It was probably a bug that has been fixed. The code comment feature has been changed recently due to performance issues.
If it is still doing it sure and we can refer to QA.
Cheers
@ Salman2301
Thank you for this clear and simple code! I have been losing my mind over this.