Hi!
I need a little help with this code:
import wixData from ‘wix-data’;
$w.onReady(() => {
wixData.query('Type')
.find()
.then(res => {
let options = [{ “value”: “”, “label”: “All Categories” }];
options.push(...res.items.map(type => {
return { “value”: type.search, “label”: type.search };
}));
$w("#dropdownfilter").options = options;
})
});
let lastFilterSearch;
let lastFilterType;
let debounceTimer;
export function searchbar_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w("#searchbar").value, lastFilterType);
}, 200);
}
function filter(search, type) {
let count = $w(“#dataset2”).getTotalCount();
if (lastFilterSearch !== search || lastFilterType !== type) {
let newFilter = wixData.filter();
if (search)
newFilter = newFilter.contains('town', search);
if (type)
newFilter = newFilter.eq('category', type);
$w("#dataset2").setFilter(newFilter);
lastFilterSearch = search;
lastFilterType = type;
}
$w("#dataset2").onReady(() => {
if (count > 0) {
$w(“#text19”).hide();
$w(“#text19”).collapse();
$w(“#gallery1”).expand();
$w(“#gallery1”).show();
}
if (count === 0) {
$w(“#text19”).show();
$w(“#text19”).expand();
$w(“#gallery1”).collapse();
$w(“#gallery1”).hide();
}
});
}
export function dropdownfilter_change(event, $w) {
filter(lastFilterSearch, $w("#dropdownfilter").value);
}
I’m trying to get the ‘‘NO RESULTS FOUND’’ message when someone does a search and there aren’t any results. With provided code, I am getting that message but with a huge delay when filtered which causes complete unfunctional-wrong search results.
Any help?
Thanks in advice!