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) .
The code I use in my website for filter function.
import wixData from 'wix-data'; export function button18_click(event, $w) { $w("#dataset1").setFilter( wixData.filter() .contains("JobType", $w('#dropdown1').value) .contains("Industry1", $w('#dropdown2').value) .contains("Location",$w('#dropdown3').value) .contains("Salary",$w('#dropdown4').value)) .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.
Please help!
I want the same exact code to reset my selection tags unlike dropdowns but the code doesnt seem to work it shows multipe errors starting with .then.
starting with .then
}):
}
@akawata
Regarding your problems..
1. How to reset the dropdowns to default values:
$w(“#dataset1”).setFilter(wixData.filter()) .then(()=>{ $w("#dropdown1").value = ""; $w("#dropdown2").value = ""; $w("#dropdown3").value = ""; $w("#dropdown4").value = ""; })
2. 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:
$w(“#dataset1”).setFilter(wixData.filter() .contains("JobType", $w('#dropdown1').value) .contains("Industry1", $w('#dropdown2').value) .contains("Location",$w('#dropdown3').value) .contains("Salary",$w('#dropdown4').value) ) .then(()=>{ let count = $w("#dataset1").getTotalCount() if(count === 0){ $w("#textNoResults").show(); $w("#repeater1").hide(); }else{ $w("#textNoResults").hide(); $w("#repeater1").data = results.items; })
Good luck!
Tiaan
[@akawata] The way you remove a filter and reload all items in the repeater is to give the setFilter function an empty filter like this: $w(“#dataset1”).setFilter(wixData.filter()); Et voilà!