I am trying to build my own product gallery using a repeater. Id like to filter the dataset connected to the repeater using radio buttons. I am currently testing this with just a single button but when I set the datasets filter, its not working. Ive tried multiple different things but this is what I have right now.
How can I use a button to filter store collections in my repeater?
export function button112_click(event) {
$w("#dataset1").setFilter( wixData.filter()
.hasSome("collections", ["Immune Support"])
)
.then( () => {
console.log("Dataset is now filtered");
} )
.catch( (err) => {
console.log(err);
} );
}
Hi Cody,
You have to know the ID value of the collection to be able to filter on the collections field of the stores/products collection. To obtain those IDs, Dataset2 in this code is tied to the stores/collections collection. This is arbitrarily grabbing up to 10 collections; adjust as needed.
$w.onReady(function () {
$w("#dataset2").onReady( () => {
$w("#dataset2").getItems(0,10)
.then((result) => {
let colls = result.items;
// loop through and create array to feed dropdown
let opts = [], opt = {};
for (var i = 0; i < colls.length; i++) {
let item = result.items[i];
opt = {"value": item._id, "label": item.name};
opts.push(opt);
}
$w("#dropdown1").options = opts;
})
});
});
export function dropdown1_change(event) {
$w("#dataset1").setFilter( wixData.filter()
.eq("collections", event.target.value)
)
.then( () => {
console.log("Dataset is filtered");
} )
.catch( (err) => {
console.log(err);
} );
}