Hello, i tried searching the forum and google but still cannot find good answer on this.
After i found a successful code in doing filter, now im having a hard time for a solution where
you can choose show all on a drop box to reverse the filter.
I have 3 option on a dropdown box
- optional tours
- group departure
- free and easy
i’d like to add option SHOW ALL and filter will be reversed and show all items (inside a repeater)
here’s the code im using for filter.
import wixData from ‘wix-data’;
$w.onReady(() => {
wixData.query('ShowAll')
.find()
.then(res => {
let options = [{“value”: “ShowAll”, “label”: “All Tours”}];
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_1(event, $w) {
//Add your code for this event here:
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w("#searchbar").value, lastFilterType);
},200);
}
function filter(search, type) {
if (lastFilterSearch !== search || lastFilterType !== type) {
let newFilter = wixData.filter();
if (search)
newFilter = newFilter.contains('title',search);
if (type)
newFilter = newFilter.eq('tourCategory', type);
$w("#dataset1").setFilter(newFilter);
lastFilterSearch = search;
lastFilterType = type;
}
}
export function dropdownfilter_change(event, $w) {
filter(lastFilterSearch, $w("#dropdownfilter").value);
}
Hope someone can help me