Thanks in advance for the help! I’ve looked around for a simple answer for this, and I’ve struggled to find one that makes sense for a novice coder like me. I have a repeater that displays rows from my dataset, called #profiles. I created a search bar (#iSearch) that, on keypress, I would like to filter my dataset to only rows containing that information. I started with one field, ‘description’, and below is the code. It actually works, and it’s based on this video here.
import wixData from "wix-data";
export function iSearch_keyPress(event) {
filter($w('#iSearch').value);
}
function filter(search) {
$w('#profiles').setFilter(wixData.filter().contains('description',search));
}
What I’d like to do is add an “or” function, so I can see if the provided text is in any field in the dataset, such as another field called ‘institution’ or ‘services’. I tried the code below, but it still only searches the ‘description’ field and ignores the ‘institution’ field.
function filter(search) { $w('#profiles').setFilter(wixData.filter().contains('description' || 'institution',search));
}
Thanks for your help! I certainly looked at all the information, but I’m afraid I don’t know how I’d go about adjusting it to my own filter. I’d just like the filter to apply to multiple fields.
Appreciate your patience. I did my best to integrate that or() function, and I can get the code inside the function to work (calling it here to filter the “institution” field), but now the previous filter (for the “description” field) isn’t responding.
import wixData from "wix-data";
export function iSearch_keyPress(event) {
filter($w('#iSearch').value);
}
function filter(search) {
$w('#profiles')
.setFilter(wixData.filter()
.contains('description',search)
.or(
$w('#profiles').setFilter(wixData.filter().contains('institution',search))
)
);
}
function filter(search) {
let filter = wixData.filter().contains('description',search)
.or(wixData.filter().contains('institution',search));
$w('#profiles').setFilter(filter);
}
This is exactly what I needed, thank you. I kinda see how it works, and I’m even able to expand it to include more and more data fields. I appreciate your help, this is exactly what I was hoping for.