Isn't it possible to filter by category using a dataset linked to the Events collection?

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.

Im having the same issue, have you found a way to solve this?

When logging the contents of the dataset, the categories field is empty

{
    ...
    "status": "SCHEDULED",
    "categories": [],
    ...
}

When I need to filter data, I have given up on using datasets…I query the collection directly and populate the repeater from the resulting array and update it each time I change filtering. It’s easier to control how you filter things that way…more work to set up but more control of the data.

Why not using Wix-Data, right from the beginning?
In most cases, you will end with using Wix-Data instead of using datasets, especially when you have a more complex setup.

Furthermore, you will have much more flexibility of how to setup your connections and how to structure your database.

Exactly where I ended up…after a lot of heartburn and anguish!