# Search Function on database

**URL:** <https://forum.wixstudio.com/t/search-function-on-database/27966>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 2, 2018, 7:21pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966 "2018-02-02T19:21:26Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 2, 2018, 7:21pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/1 "2018-02-02T19:21:26Z")

</div>

Hi i just found this video [Wix Code | How to Create a Search for Your Database - YouTube](https://www.youtube.com/watch?time_continue=117&v=Hx7_8-lRsW0) and i would like to recreate on my site, this is the code i entered but doesn’t work. please help…

import wixData from “wix-data”; $w.onReady(() =\> { wixData.query(‘Continents’) .find() .then(res =\> { let options = [{“value”: ‘’, ‘label’: ‘All Continents’}]; options.push(…res.items.map(continent =\> { return {‘value’: ‘label’" continent.title}; })); $w(‘#iContinent’).options = options; ]} }); let lastFilterTitle; let lastFilterContinent; let debounceTimer; export function iTitle\_keyPress () { if (debounceTimer) { clearTimeout(debounceTimer); debounceTimer = undefined; } debounceTimer = setTimeout(() =\> { filter($w(‘#iTitle’).value, lastFilterContinent); }, 200,); } function filter(title,continent) { if (lastFilterTitle !== title) || lastFilterContinent !== continent) { let newFilter = wixData.filter(); if (title) newFilter = newFilter.contains(‘articleTitle’, title); if (continent) newFilter = newFilter.eq(‘continent’, continent); $w(‘#dataset1’).setfilter(newFilter); lastFilterTitle = title; lastFilterContinent = continent; } } export function iContinent\_change(); filter(lastFilterTitle, $w(‘#iContinent’).value);

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [February 4, 2018, 9:36am UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/2 "2018-02-04T09:36:25Z")

</div>

Hi Luca,  
This code is not readable in this format.  
Please elaborate what is the scenario and what you would like to achieve.  
Roi

---

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 4, 2018, 11:20am UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/3 "2018-02-04T11:20:55Z")

</div>

I need to replicate the example from the video above, basically a search + filter for database using the repeater. i am not very good with code but some more example would be very helpful i think.  
Regarding the code somebody gave this code: [Totally Codable - Trusted Velo Community](https://www.webixdesigns.com/forum/wix-code-for-all/search-on-keypress-with-dropdown). Thanks.

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [February 4, 2018, 12:21pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/4 "2018-02-04T12:21:26Z")

</div>

Hi Luca,  
Which part of the code is not working ? Can you more specific ?  
Roi

---

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 4, 2018, 1:10pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/5 "2018-02-04T13:10:51Z")

</div>

![](https://us1.discourse-cdn.com/wix/original/3X/2/1/2168eb214115344b07a16d2497dcc638d497f80e.png)  
I am trying to send you a screenshot but not luck, cannot upload any file…

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [February 4, 2018, 1:16pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/6 "2018-02-04T13:16:59Z")

</div>

You can paste here a link to your site and explain.  
Roi

---

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 4, 2018, 1:18pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/7 "2018-02-04T13:18:55Z")

</div>

I uploaded the screenshot, that’s the link [https://lucasgariglia.wixsite.com/wixcode](https://lucasgariglia.wixsite.com/wixcode)

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [February 4, 2018, 2:23pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/8 "2018-02-04T14:23:42Z")

</div>

Hi again,  
The code that you copied from the link above has many syntax errors.  
I recommend to follow the tutorial and to write it on your own.  
That way you’ll better understand the code.  
Moreover, you need to adapt is to your elements a database collections name.

[![](https://us1.discourse-cdn.com/wix/original/3X/2/8/28debde4ec57c2912a3d6fb5761adcf652870d23.jpeg "Wix Code | How to Create a Search for Your Database") ](https://www.youtube.com/watch?v=Hx7_8-lRsW0)

Roi

---

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 4, 2018, 2:26pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/9 "2018-02-04T14:26:20Z")

</div>

Is it possible to get an example from that video so i can inspect in the editor how the database was set with all the elements ?

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [February 5, 2018, 12:38pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/10 "2018-02-05T12:38:57Z")

</div>

Good luck!

```javascript
import wixData from 'wix-data';

$w.onReady(() => {
	wixData.query('Continents')
		.find()
		.then(res => {
			let options = [{
				"value": '',
				'label': 'All Continents'
			}];
			options.push(...res.items.map(continent => {
				return {
					'value': continent.title,
					'label': continent.title
				};
			}));
			$w('#iContinent').options = options;
		});
});

let lastFilterTitle;
let lastFilterContinent;

let debounceTimer;
export function iTitle_keyPress(event, $w) {
	if (debounceTimer) {
		clearTimeout(debounceTimer);
		debounceTimer = undefined;
	}
	debounceTimer = setTimeout(() => {
		filter($w('#iTitle').value, lastFilterContinent);
	}, 200)
}

function filter(title, continent) {
	if (lastFilterTitle !== title || lastFilterContinent !== continent) {
		let newFilter = wixData.filter();
		if (title)
			newFilter = newFilter.contains('articleTitle', title);
		if (continent)
			newFilter = newFilter.contains('continent', continent);
		$w('#dataset1').setFilter(newFilter);
		lastFilterTitle = title;
		lastFilterContinent = continent;
	}
}
export function iContinent_change(event, $w) {
	filter(lastFilterTitle, $w('#iContinent').value);
}

```

---

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 5, 2018, 2:08pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/11 "2018-02-05T14:08:24Z")

</div>

Thanks, i will give it a try…

---

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 5, 2018, 2:57pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/12 "2018-02-05T14:57:51Z")

</div>

Still no luck the video doesn’t explain in details how to set the repeater and the database…

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [February 5, 2018, 3:18pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/13 "2018-02-05T15:18:53Z")

</div>

Hi Luca,  
There is lots of information in this forum and the [help center](https://support.wix.com/en/wix-code/wix-code-basics) .  
This [tutorial](https://support.wix.com/en/article/displaying-dynamic-data-in-a-repeater) will help to connect the repeater to the database collection.  
Roi

---

<div class="post-metadata">

**Author:** ![luca-sgariglia](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/luca-sgariglia/32/774_2.png) [@luca-sgariglia](https://forum.wixstudio.com/u/luca-sgariglia)\
**Post date:** [February 5, 2018, 3:29pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/14 "2018-02-05T15:29:44Z")

</div>

I configured and connected the repeater but still nothing, how about the drop down elements, ho w do i need to name them? Not very Helpful i start to be frustrated as i wix user i know almost nothing to code!!!  
What i ask here to create this scenario as an example in the resources page as i learned a lot from there, but like this i am like blind…

---

<div class="post-metadata">

**Author:** ![roi-bendet](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/roi-bendet/32/1283_2.png) [@roi-bendet](https://forum.wixstudio.com/u/roi-bendet)\
**Post date:** [February 6, 2018, 8:50am UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/15 "2018-02-06T08:50:50Z")

</div>

Hi,  
Some coding skill are required in order to make it done.  
You can hire an expert in [Wix Arena](https://www.wix.com/arena/info/how-it-works) .  
Did you connect the elements inside the repeater to the dataset ?  
Roi

---

<div class="post-metadata">

**Author:** ![justin-singh](https://avatars.discourse-cdn.com/v4/letter/j/d78d45/32.png) [@justin-singh](https://forum.wixstudio.com/u/justin-singh)\
**Post date:** [February 15, 2018, 8:20pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/16 "2018-02-15T20:20:40Z")

</div>

Hi Roi,

I am having some trouble filtering dynamic content as well. I am just having issues populating the dropdown box with the items in the collection. The search function works as shown but I am unable to populate the dropdown choice with the ones on the collection and add a ALL option as well. Not sure what to do. Here is the link of the page. [https://midknightgenius.wixsite.com/lara/collection](https://midknightgenius.wixsite.com/lara/collection)

The dropdown list only contains the default items.

---

<div class="post-metadata">

**Author:** ![webdeveloperssp](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/webdeveloperssp/32/18069_2.png) [@webdeveloperssp](https://forum.wixstudio.com/u/webdeveloperssp)\
**Post date:** [April 7, 2020, 10:00am UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/17 "2020-04-07T10:00:21Z")

</div>

Hi There,  
I am also facing the issue with dropdown.  
Can you please help me with this

---

<div class="post-metadata">

**Author:** ![kclopresto](https://avatars.discourse-cdn.com/v4/letter/k/ad7895/32.png) [@kclopresto](https://forum.wixstudio.com/u/kclopresto)\
**Post date:** [April 9, 2020, 10:10pm UTC](https://forum.wixstudio.com/t/search-function-on-database/27966/18 "2020-04-09T22:10:06Z")

</div>

The Search command is working for me. I built a simple database, copy and pasted this code and when I type in a value into the search bar nothing filters.

**import** wixData **from** ‘wix-data’;  
$w.onReady( **function** () {  
//TODO: write your page related code here…  
});  
export function input1\_keyPress(event) {  
**let** SearchValue = $w(‘#input1’).value;  
$w(‘#dataset1’).setFilter(wixData.Filter().contains(‘pos’, ‘SearchValue’))  
}
