# Searching a Database / Displaying in Repeater

**URL:** <https://forum.wixstudio.com/t/searching-a-database-displaying-in-repeater/38688>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [October 31, 2019, 11:26am UTC](https://forum.wixstudio.com/t/searching-a-database-displaying-in-repeater/38688 "2019-10-31T11:26:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hello-kurious-katie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hello-kurious-katie/32/14546_2.png) [@hello-kurious-katie](https://forum.wixstudio.com/u/hello-kurious-katie)\
**Post date:** [October 31, 2019, 11:26am UTC](https://forum.wixstudio.com/t/searching-a-database-displaying-in-repeater/38688/1 "2019-10-31T11:26:27Z")

</div>

I’m trying to add a product search feature to my website, as the current standard Wix search feature searches the WHOLE website and lacks customisation.

I have tried multiple ways, but am struggling at the moment, due to lack of time and energy (a bad strain of the flu). However, I really need this working soon ☹

Can anyone lend a hand and help me out with the code?

What I need:

- The search bar (#searchBox) to be able to search the database (#dataset1) for any word to match in the field key ‘name’.
- For the search bar to work when ‘enter/return’ is pressed (no button).
- For the search bar to then take customer from any page to the ‘search-results’ page (link below).
- For the results to then be displayed within the repeater (#searchResults).

Example of my website, if you need to take a look:  
[https://kurious-katie.wixsite.com/website-1/search-results](https://kurious-katie.wixsite.com/website-1/search-results)

If you need anymore information, please let me know 🙂  
Thanks in advance for any help!

---

<div class="post-metadata">

**Author:** ![samuele](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/samuele/32/10102_2.png) [@samuele](https://forum.wixstudio.com/u/samuele)\
**Post date:** [October 31, 2019, 3:36pm UTC](https://forum.wixstudio.com/t/searching-a-database-displaying-in-repeater/38688/2 "2019-10-31T15:36:34Z")

</div>

You can achieve your goal by doing the following:

1. Follow the example in this tutorial: [https://support.wix.com/en/article/corvid-tutorial-adding-collection-data-search-functionality](https://support.wix.com/en/article/corvid-tutorial-adding-collection-data-search-functionality)
2. Use the onKeyPress event instead on button click: [https://www.wix.com/corvid/reference/$w.TextInputMixin.html#onKeyPress](https://www.wix.com/corvid/reference/$w.TextInputMixin.html#onKeyPress)
3. Replace the table in the example with a repeater. You can find more information on how to display information on a repeater here: [https://www.wix.com/corvid/reference/$w.Repeater.html#data](https://www.wix.com/corvid/reference/$w.Repeater.html#data)  
Should you wish to display results on a different page, you can redirect to the page using wixLocation.to() . To learn more:[https://www.wix.com/corvid/reference/wix-location.html#Location](https://www.wix.com/corvid/reference/wix-location.html#Location)

---

<div class="post-metadata">

**Author:** ![hello-kurious-katie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/hello-kurious-katie/32/14546_2.png) [@hello-kurious-katie](https://forum.wixstudio.com/u/hello-kurious-katie)\
**Post date:** [October 31, 2019, 4:03pm UTC](https://forum.wixstudio.com/t/searching-a-database-displaying-in-repeater/38688/3 "2019-10-31T16:03:03Z")

</div>

I’ve had a little play (I’m not much of a coder), so please excuse if this is completely wrong.

Can you take a look and tell me how I would improve this?  
I can’t seem to understand how to use the onKeyPress event for using ‘enter’ to search.  
Also, can’t understand how to use the wixLocation.to() to work. I’m assuming I need to use **“/localPageURL?queryParam=value:”** but can’t understand how to search with the inputted word?

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

$w.onReady(function () {
$w("#searchBox").show();
$w("#searchResults").show();
$w("#button3").show();
})

export function searchButton_click(event) {
// Runs a query on the "products" collection
wixData.query("dataset1") 
 // Query the collection for any items whose "Name" field contains  
 // the value the user entered in the input element
  .contains("name", $w("#searchBox").value)
  .find() // Run the query
    .then((results) => {
        console.log("Dataset is now filtered");
 let repeaterItems = $w('#searchResults').data;
        $w("#searchResults").data = results.items;

    }).catch((err) => {
        console.log(err);
    });
    $w("#searchResults").expand(); 
   }

```

If you could help, I would be so grateful! 🙂
