I follow the instruction on this video, and added 4 dropdowns and a search button to filter dataset connected to a repeater. https://www.youtube.com/watch?v=QhMKnm1f6EU
Once I use one of the dropdowns and press search button, it filters data properly , however…
PROBLEM
The repeater remains as it is filtered.
When I do a new search using any of the dropdowns, it doesn’t seem to filter “all data” but it filters “only what remains with previous search”.
I am making a job search page for jobseekers, so I expect users to do a new search again and again using different categories (ex. search by location, search by job type, search by industry) .
.then((results) => {
console.log("Dataset is now filtered");
$w("#repeater1").data = results.items;
}). catch ((err) => {
console.log(err);
$w("#repeater1").expand();
})
}
So, I want to add “Refresh Button” in the page, so that users can start fresh search. I already checked some existing forum on refresh function, but it was too difficult for me to understand… because, I’m not a coder. I only code when I need to add a function on my website. I usually just search copy and paste code.
$w(" #dataset1 ").setFilter(wixData.filter());
This made my “clear” button works exactly the way I want!!!
Thank you sooooo much, Steven!
Then, I’m facing another problem…(T_T)
Problem 1:
I have four dropdowns.
The very first search, filter works fine; if a user use only one dropdown, it filters the repeater properly. But, after pressing “clear” button, then search again, it no longer works like that; Nothing shows on the repeater, unless all four dropdowns choices matches…
Problem 2:
It would be nice if a user press “clear” button, all four dropdown boxes return to default placeholder text (i.e. a user search for “IT job”, then press “clear”, the dropdown returns to “search by Industry” instead of remain as “IT job”.)
How to show the ‘No Results’ message on screen - add a normal text element and name it something like textNoResults. Then, in the section of the .then() function write a little bit of code to display that message is no results have been found like so:
Line 18 shows red dot which means you have error on that line, with the red line underlining where your error is in your code.
Simply delete the ‘)’ in your code and see what happens.
Basically you just need to make sure that in your code you have a matching number (pairs) of curly brackets and parentheses, which are the { and } and the ( and ) in your code.
@akawata@givemeawhisky Actually indentation of your code would help you a lot. The red dot is because your if/else conditional is not closed before closing the .then().
Your code should read (I have included indentations to show the help they give ;-)).
// the following code starts at your line 10 & inserts a “}” on a line above line 18.
.then(() => {
let count = $w(“#dataset1”).getTotalCount();
if (count === 0) {
$w(“#textNoResults”).show();
$w(“#repeater1”).hide();
} else {
$w(“#textNoResults”).hide();
$w(”#repeater1”).data = results.items;
} // <===== this is the missing line!
})
One other thing to note - you do not have a results variable anywhere so the assignment on line 17 will likely show your next red dot ;-). Since you probably have the dataset you are filtering bound to $w(“#repeater1”) there isn’t a need to assign a value to its .data value. The repeater should update when the filter completes. You should probably make line 17:
$w(“#repeater1”).show();
since you hide it in the if() part of your test you should show it in the else part.
Thank you sooo much!
Your code works perfectly!!!
Now, all my problems have been solved. I couldn’t have done without your help!
Once again, thank you all!
Hmmm. It might be to do with the fact that the dropdown are filtering the dataset via being connected to them? It might work better if they are filtering via code
@noahlovell Aha, yes. That could be it! I’m not a coder so I always try without code. But I have the code for the filters somewhere, I’ll try that. Thanks for the helpful hints, really useful to get someone else’s perspective!