I have successfully followed this tutorial for my gallery:
However, I am having trouble with one of the last steps where I have an “All Countries” option for the dropdown. In my context, it’s “All Makes” for automobiles. However, when I select it, all my photos disappear. The rest of the filter works, but it’s acting like it’s looking for “All Makes” as opposed to using that as an open filter.
Here is the code I’m using. Any help is appreciated!
import wixData from 'wix-data';
$w.onReady(() => {
wixData('Make')
.find()
.then(res => {
let options = [{"value": '', 'label': 'All Makes'}];
options.push(...res.items.map(make => {
return {'value': make.search, 'label': make.search};
}));
$w('#iMake').options = options;
})
});
let lastFilterSearch;
let lastFilterMake;
let debounceTimer;
export function iSearch_keyPress(event, $w) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
if (debounceTimer) {
clearTimeout(debounceTimer);
}
debounceTimer = setTimeout(() => {
filter($w('#iSearch').value, lastFilterMake);
}, 200);
}
function filter(search, make) {
if (lastFilterSearch !== search || lastFilterMake !== make) {
let newFilter = wixData.filter();
if (search)
newFilter = newFilter.contains('model', search);
if (make)
newFilter = newFilter.eq('make', make);
$w('#cardata').setFilter(newFilter);
lastFilterSearch = search;
lastFilterMake = make;
}
}
export function iMake_change(event, $w) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
filter(lastFilterSearch, $w('#iMake').value)
}
Bonus question:
Currently, the search bar sorts through the field “model” from my dataset. Is it possible for this bar to filter through multiple columns in a data set and return results matching “model”, “year”, etc?
When I change my change event to reflect what you have provided I get an error telling me ‘value’ is not defined. I appreciate the help.
export function iMake_change(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
value === "" ? $w('#cardata').setFilter() : filter(lastFilterSearch,
$w('#iMake').value);
}
@jonatandor35 If I do that I get functionality back, but the original issue of the “All Makes” option filtering everything out persists.
export function iMake_change(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#iMake').value === "" ? $w('#cardata').setFilter() : filter(lastFilterSearch,
$w('#iMake').value);
}
export function iMake_change(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
let filterType = $w('#iMake').value;
if (filterType === "All Makes"){
$w('#cardata').setFilter(wixData.filter());
} else{
$w('#cardata').setFilter(wixData.filter().contains("make", filterType));
}
}
@jonatandor35 It was both, but what should the value have been to properly make your code work? I tried “null” but that wasn’t working. If there is a better way than having it reset the filter with All Makes I am totally open to it.