Hi all,
I’m new to using WIX and hoping this community can help set me straight on how to use filters on dynamic datasets.
Background : I have a collection (named “cars”) and a dynamic page that displays each car in a repeater. Some of the cars are “For Sale” while others are not. when the page first opens, I’d like all cars to display. At the top of the page is a switch. If the user turns on the switch, then I’m hoping the display can only show the cars that have an ItemStatus value of “For Sale”. It seems simple, but I’m somewhat stumped.
Result : When the page first loads, it loads showing all rows in the collection (unfiltered). When I click the switch, nothing is displayed. When I turn the switch back off everything is displayed again.
Below is the code that I have in the OnClick event of the switch:
*** Start of code ***
import wixData from ‘wix-data’;
export function switch1_click(event) {
**let** bool = $w("#switch1").checked; // get the checked value of "switch1"
**if** (bool === **false** ) {
//Switch is ON, apply filter
**let** filtervalue = "For Sale";
$w("#dynamicDataset").setFilter(wixData.filter()
.eq("ItemStatus", filtervalue)
);
console.log("Filter is on");
} **else** {
//switch is OFF, remove filter
$w("#dynamicDataset").setFilter( wixData.filter() );
console.log("Filter is off");
}
}
*** End of Code ***
Thanks in advance!