We are setting up a portfolio with projects that belong to one or more category which we've represented in our database as tags. We have a dropdown menu that contains all of the tags we've used and we'd like to filter the projects that appear based on the category (market) that is selected - just one category at a time.
I got fairly far using the code described in this tutorial
https://www.youtube.com/watch?v=Hx7_8-lRsW0&ab_channel=Wix.com
but I cannot figure out how to compare the dropdown selection with the the tag field (market) in the dataset to see if it contains the specific tag.
Can someone assist me with syntax for this? I've done quite a bit of searching but to no avail.
Thanks in advance.
// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query('Projects');
});
let lastFilterTitle;
let lastFilterMarket;
let debounceTimer;
export function iName_keyPress(event) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(()=> {
filter($w('#iName').value, lastFilterMarket);
}, 200);
// console.log($w('#iName').value);
filter($w('#iName').value);
}
function filter(title, market) {
if(lastFilterTitle !== title || lastFilterMarket !== market) {
let newFilter = wixData.filter();
if(title)
$w('#projectData').setFilter(wixData.filter().contains('title',title));
if(market)
$w('#projectData').setFilter(wixData.filter().contains('market',market));
$w('#projectData').setFilter(newFilter);
lastFilterTitle = title;
lastFilterMarket = market;
}
}
export function iMarket_change(event, $w) {
filter(lastFilterTitle, $w('#iMarket').value);
}
Have you seen this example? https://www.wix.com/corvid/example/filter-with-multiple-options
Hope it helps!
I don't get it either - the TAG fonction in the collection is useless if it can't be use to filter... Actually the option "filter with the datas from user" in present for filtering a gallery wich content a collection but it's unaccessible.