Hi everyone,
I’m new to Wix Code, so I might be asking a stupid question here.
I’ve set up a dynamic page with repeaters and I want to filter the dataset with a few different filters. I’ve created the input field for the destination filter and it works fine. I’ve added a dropdown filter wich refers to a database o months. The items have a field stating what month or months they refer to.
The first problem is that if I chose a month for wich there is no item, once I change my choice and go on a month where there is supposed to be at least one item, it won’t show anything.
Second problem is that it can’t seem to go back to all the items if I choose the “starting” option on the dropdown menu.
Sorry if I’m not being very clear, but I can’t seem to figure this problem out.
Thank you so much for your help.
Here is my code
$w.onReady (() => {
wixData.query(‘periodo’)
.find()
.then(res => {
let options = [{“value”: ‘’, ‘label’: ‘periodo’}];
options.push(…res.items.map(periodo => {
return {“value”: periodo.title, ‘label’: periodo.title};
}));
$w(‘#iPeriodo’).options = options;
})
});
let lastFilterDestinazione;
let lastFilterPeriodo;
let debounceTimer;
export function iDestinazione_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iDestinazione’).value, lastFilterPeriodo);
}, 200)
}
function filter(destinazione, periodo) {
if (lastFilterDestinazione !== destinazione || lastFilterPeriodo !== periodo) {
let newFilter = wixData.filter();
if (destinazione)
newFilter = newFilter.contains('destinazione', destinazione);
if(periodo)
newFilter = newFilter.eq('periodo', periodo);
$w('#dataset1').setFilter(newFilter);
lastFilterDestinazione = destinazione;
lastFilterPeriodo = periodo;
}
}
export function iPeriodo_change(event, $w) {
filter(lastFilterPeriodo, $w(‘#iPeriodo’).value);
}