Custom Store Filters (color)

Question:
Filter a dataset by color

Product:
Wix Studio Editor.]

What are you trying to achieve:
I want to create an additional filter function by product color for a custom product gallery.

Bildschirmfoto 2024-02-22 um 11.40.03

What have you already tried:
Done this:

Additional information:
Can I use this?

Product Options (productOptions)

How can I add a filter mentioned above? Best case scenario should be that only colors available under Stores/Products should be displayed. OnClick on a color field items should be filtered additionally to other flters.

Hi I tried around everything possible but nothing works with this code:

// filter a dataset by color

import wixData from 'wix-data';

$w('#myDataset').setFilter(wixData.filter()
    .hasSome('productOptions.color.value', ['#0000ff', ...])
)

Edit: The button (event handler) is now working. However, no more items are displayed after filtering, although “#ff0000” appears in the collection. What could be the reason for this?

Final code:

import wixData from 'wix-data';

 $w('#filterButton').onClick(() => {
    // Apply the filter to the dataset
    $w('#storesProducts').setFilter(wixData.filter()
        .hasSome('productOptions.color.value', ['ff0000'])
    )
    .then(() => {
        console.log("Dataset is now filtered");
    })
    .catch((err) => {
        console.log(err);
    });
});