Hello all, and thank you for taking the time to read this.
I’m am currently creating a repeater/database search. The purpose is for visitors to be able to search through our list of inductees. At the moment there are three search filters: a search bar through which users can search by Inductee Name, and two dropdown menus for users to filter by year inducted and category inducted.
The code as it is works perfectly fine. However, I would like to add the ability for the search bar to search another field that is not visible in the repeater, but within the dataset. I would like users to be able to search members names, field name “members,” so that they can search for members of a specific band or see all the entries that come up for a person who might have been inducted multiple times.
I am not sure where to add this in my current code, and would really prefer not to have to rewrite large chunks of it if there is an easy solution. Thank you in advance for whoever lends me their time!
Here are some pictures so that you can see the code in action:
The code:
import wixData from "wix-data";
$w.onReady(function(){
loadYears()
});
$w.onReady(function(){
loadCategory()
});
function loadYears() {
wixData.query('Inductees').limit(1000).ascending("year").distinct("year").then ((results) => {
let distinctList = results.items.map(element => { return {label: element, value: element};})
distinctList.unshift({"value": "", "label": "All Years"})
$w("#iYear").options = distinctList
})
}
function loadCategory() {
wixData.query('Inductees').limit(1000).ascending("category").distinct("category").then ((results) => {
let distinctList = results.items.map(element => { return {label: element, value: element};})
distinctList.unshift({"value": "", "label": "All Categories"})
$w("#iCategory").options = distinctList
})
}
let lastFilterName;
let lastFilterYear;
let lastFilterCategory;
let debounceTimer;
export function iName_keyPress(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w('#iName').value, lastFilterYear, lastFilterCategory);
}, 200);
}
function filter(name, year, category){
if (lastFilterName !== name || lastFilterYear !== year || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (name)
newFilter = newFilter.contains('name', name);
if (year)
newFilter = newFilter.eq('year', year);
if (category)
newFilter = newFilter.eq('category', category)
$w('#dataset1').setFilter(newFilter);
lastFilterName = name;
lastFilterYear = year;
lastFilterCategory = category;
}
}
export function iYear_change(event) {
filter(lastFilterName, $w('#iYear').value);
}
export function iCategory_change(event) {
filter(lastFilterName, lastFilterYear, $w('#iCategory').value);
}