I have written code to filter a repeater with user input (two search fields and a dropdown), which is working. However, I want to only search a subset of the database, so only return rows that match a static query I define beforehand, as well as the user input search criteria.
I thought I could set a filter on the dataset. That does filter the dataset, but only before the search is executed. Once the user submits search criteria, the repeater searches the whole dataset, ignoring the filter.
So I assume I need a bit of static code in my query in addition to the user input query criteria. But I don’t know how to add this. Here is the code I’m currently using to collect user input and filter the repeater.
I’d like to add a static query criteria that checks to see if the Approved field is true and only return rows that both match the user input search criteria and are Approved. I appreciate any help.
// This code searches and filters the dataset and displays it in the repeater
let lastFilterName;
let lastFilterDescription;
let lastFilterVertical;
function filter (name, description, vertical, mentor) {
if (lastFilterName !== name || lastFilterDescription !== description || lastFilterVertical !== vertical ) {
let newFilter = wixData.filter();
if (name) {
newFilter = newFilter.contains( “fullName” , name)
}
if (description) {
newFilter = newFilter.contains( “longDescription” , description)
}
if (vertical) {
newFilter = newFilter.contains( “vertical” , vertical)
}
$w( "#dataset1" ).setFilter(newFilter);
lastFilterName = name;
lastFilterDescription = description;
lastFilterVertical = vertical;
}
}
export function searchButton_click(event, $w) {
$w( “#dataset1” ).setFilter(wixData.filter()
.contains( ‘fullName’ , $w( ‘#sName’ ).value)
.contains( ‘longDescription’ , $w( ‘#sDescription’ ).value)
.contains( ‘vertical’ , $w( ‘#sVertical’ ).value)
)
.then((results) => {
console.log( "Dataset is now filtered" );
$w( "#teamRepeater" ).data = results.items;
}). **catch** ((err) => {
console.log(err);
});
$w( "#teamRepeater" ).expand();
}