Hello! I need help!
I’ve created a search bar on my page that filters a repeater. The repeater is connected to a dataset, which populates the content.
The search bar currently searches by “title”, which is one of the columns in the dataset. (see image below)
I WANT the search bar to filter the results based on data from several of the columns in the dataset. Namely, I’d love for it to search both the “title” column AND the “tags” column that I’ve created. For the life of me, I can’t seem to figure out how to add this second “tags” parameter…
Currently when I search any of the tags I have, the repeater just goes blank.
Please Help?
My Database:
My current code:
import wixData from “wix-data”;
$w.onReady(() => {
});
let lastFilterTitle;
let lastFilterContinent;
let debounceTimer;
export function iTitle_keyPress_1(event, $w) {
if (debounceTimer) {
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(’ #iTitle ').value, lastFilterContinent);
}, 500);
}
function filter(title, tags) {
if (lastFilterTitle !== title || lastFilterContinent !== tags) {
let newFilter = wixData.filter();
if (title)
newFilter = newFilter.contains(‘title’, title);
if (tags)
newFilter = newFilter.contains(‘tags’, tags);
$w(’ #dataset1 ').setFilter(newFilter);
lastFilterTitle = title;
lastFilterContinent = tags;
}
}
PS: Yes, I’ve watched this video 100 times… but I quite new to javascript and I need a little extra help sorting this out (Wix Code | How to Create a Search for Your Database - YouTube)
This is what the page/Searchbar/repeater looks like, on load and while searching. Works great when searching titles…
Hi,
First, where you’re setting the variables lastFilterTitle and lastFilterContinent ?
I’m not able to figure out if you want to filter title and tags , or title or tags . The if statements work such that if the second one is true, it overwrites the first one. Is that what you want.
Please explain what exactly you are trying to search for.
Yisrael
Hello Yisrael! Thanks so much for your response!
"where you’re setting the variables lastFilterTitle and lastFilterContinent ?"
-I honestly don’t know the answer to that. That’s how illiterate I am. Much of the code has been copied from other examples I’ve seen. The “Continent” stuff I think is just left over from the example in this tutorial: ( https://www.youtube.com/watch?time_continue=117&v=Hx7_8-lRsW0 ) when I was just trying to replicate it with the same ID’s and names for everything. I see that those variable are in the code… but honestly don’t know what they do.
"I’m not able to figure out if you want to filter title and tags , or title or tags . The if statements work such that if the second one is true, it overwrites the first one. Is that what you want."
I think the “if” statement you’re suggesting is the ideal. It’s a database of resources for youth workers, so it covers topics like abuse, anxiety, depression, etc. In the repeater, only the titles are visible, but in my dataset, I’ve included a list of words (under a column titled “tags”) that relate to the title.
So a practical example:
-Someone types in “hurt”.
-There is no Title with the word hurt, but there are 2 items that have the word hurt as a “tag”. Abuse and Self-Harm.
-Both Abuse and Self-Harm appear for the user, even though they searched the word “hurt”.
OR
-Someone types in “depression”
-The item with the title “depression” pops up
-but, “Self-Harm” also pops up for them (because I have ‘depression’ as a tag for the Self-Harm item)
Make any sense?
The type of search that you would like to implement certainly sounds like a clever idea. However, this is not a trivial task for someone with no coding experience. We appreciate your interest in getting the most out of Wix Code and how much you want to learn. Please understand that if you are going to work with code extensively in the product and not just the features in the user interface, you will need to familiarize yourself with basic coding concepts to accomplish what you want. We are happy to get you pointed in the right direction and get you started with what the code should look like, but you’ll need to take it from there.
You may also want to check out the WixArena - it’s a hub where you can look for Wix Code (and other) experts for hire.
Thanks for your understanding.