Using searchbox/drop down for repeater filter. However, looking to narrow the search to specific area of database. One issue I am finding is that when search box is used it will pull search into the whole database (no matter if I use a filter on the dataset or not). So appears that using the code to set up the search boxes bypasses any filters set to the dataset.
So must set up filter within the code, but I am not much of a coder…so thoughts on how to add a filter to the “standard” code. Here is my specific code. I am wanting to filter the “category” field by specific input to that field. Say category has data of x in some, and b in some. I want to filter my search menu in this code to limit to only searching results that have x in category and not pull up all the other in database. Without such, the search attempts to pull all up all items in database and since items in repeater may not be applicable to all…it leaves an ugly page result and just an overall nuisance to a visitor.
import wixData from “wix-data”;
$w.onReady(() => {
loadMagPages();
});
let lastFilterReference;
let lastFilterCategory;
let debounceTimer;
export function iTitle_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#iTitle’).value, lastFilterCategory);
}, 500);
}
export function iCategory_change(event) {
filter(lastFilterReference, $w(‘#iCategory’).value);
}
function filter(title, category) {
if (lastFilterReference !== title || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘reference’, title);
if (category)
newFilter = newFilter.contains(‘category’, category);
$w(‘#dataset5’).setFilter(newFilter);
lastFilterReference = title;
lastFilterCategory = category;
}
}
function loadMagPages() {
wixData.query(‘MagPages’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘All Categories’}];
options.push(…res.items.map(category => {
return {“value”: category.title, “label”: category.title};
}));
$w(‘#iCategory’).options = options;
});
}
export function iTitle_change(event) {
//Add your code for this event here:
}