I wanted to customize the way the events page looks, so I built a repeater based upon a dataset linked to the Events collection.
The repeater works fine on its own but when I try to filter it by category using some simple Velo code, it shows no events. I can filter by category in the dataset settings but cannot achieve the same thing with Velo…which has me at a standstill.
Code as follows:
import wixData from 'wix-data';
$w.onReady(async function () {
$w("#categoryTags").onChange(function () {
search();
});
function search() {
let filter = wixData.filter().eq("status", "SCHEDULED");
let catIdx = $w("#categoryTags").selectedIndices;
console.log(catIdx)
let category = $w("#categoryTags").value;
console.log(category)
if (catIdx.length > 0) {
filter = filter.hasAll("categories", category)
console.log(filter)
$w("#events").setFilter(filter)
} else {
$w("#events").setFilter(filter)
//console.log("else statement used")
}
$w("#clearFilter").onClick(function () {
$w("#categoryTags").value = undefined;
$w("#events").setFilter(wixData.filter());
});
}
});
When I console.log the filter object in the first IF statement, it seems to structured exactly as I’d expect…but it just doesn’t filter the dataset. Here’s the object for one case:
This code is the same as I have used successfully in the past to filter other collections, so I am wondering if there is something special about the Events collection that prevents this filtering approach from working and whether there are workarounds that anyone can suggest?
Simon.