I have been trying to filter search my website, but for some reason my search result is blank as follows:
And this is my code
Please kindly advise what I do wrong.
Thank you in advance
Best,
ZP
I have been trying to filter search my website, but for some reason my search result is blank as follows:
Best,
ZP
See this example. You can load it into your editor, play with it, and change it to suit your needs.
Add search functionality to your site by adding input elements to the page and then adding code to enable a search.
Dear Yisrael,
I am still unable to solve this. I would like the following functions to work and 1 of them only works now.
Could you check my code and see what is wrong with it?
Thank you in advance.
import wixData from ‘wix-data’;
$w.onReady( function (){
});
export function SearchBar_keyPress(event, $w) {
let SearchValue = $w(‘#SearchBar’).value;
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘project’, SearchValue));
}
export function button2_click(event) {
$w(“#dataset1”).setFilter(wixData.filter()
.contains(“type”, $w(‘#dropdown5’).value)
.contains(“btsOrMrtStation”, $w(‘#dropdown1’).value)
.ge(“bedroom”, $w(‘#dropdown2’).value)
.between(“price”,parseFloat($w(‘#dropdown3’).value), parseFloat($w(‘#dropdown4’).value)))
.then((results) => {
console.log("Dataset is now filtered");
$w('#repeater1').data = results.items;
}). **catch** ((err) => {
console.log(err);
});
$w(‘#repeater1’).expand();
}
export function clearFilters_onClick(){
$w(‘#dataset1’).setFilter(wixData.filter(undefined));
$w(‘#SearchBar’).value = 0;
}
The SearchBar_keyPress() function needs a timeout before getting the SearchBar value. See the article Give the TextInput onKeyPress Function some time for details.
The setFilter() in the button2_click() function does not return results. See the setFilter() API for information.
To clear the filter as you are doing in clearFilters_onClick() , use an empty filter wixData.filter() as shown in the setFilter() API .
See the Search a Database example to learn how to create your own search.