Dear Wix,

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

See this example. You can load it into your editor, play with it, and change it to suit your needs.

Search a Database

Add search functionality to your site by adding input elements to the page and then adding code to enable a search.

1 Like

Dear Yisrael,
I am still unable to solve this. I would like the following functions to work and 1 of them only works now.

  1. Search Bar (Works!!)
  2. Dropdown search ***Doesn’t work
  3. Clear search ***Doesn’t work

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.