# Search dataset

**URL:** <https://forum.wixstudio.com/t/search-dataset/40738>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [October 21, 2019, 3:03am UTC](https://forum.wixstudio.com/t/search-dataset/40738 "2019-10-21T03:03:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![steviecain](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@steviecain](https://forum.wixstudio.com/u/steviecain)\
**Post date:** [October 21, 2019, 3:03am UTC](https://forum.wixstudio.com/t/search-dataset/40738/1 "2019-10-21T03:03:03Z")

</div>

Hi - I need to have a search function so users can search a dataset with their surname, and as a result the table number is displayed in the table below?

 ![](https://us1.discourse-cdn.com/wix/original/3X/f/4/f4832cc92e368af6a256b5f1677bd15c7df08da9.png)

$w.onReady( function () {  
} );  
import wixData from ‘wix-data’  
export function input1\_keyPress(event) {  
// Runs a query on the “TablePlan” collection  
wixData.get(“TablePlan”)  
// Query the collection for any items whose “Surname” field contains  
// the value the user entered in the input element  
.contains(“Surname”, $w(“#input1”).value)  
.find() // Run the query  
.then(res =\> { // Set the table data to be the results of the query  
$w(“#table1”).rows = res.items;  
});

```javascript

```

Any help would be greatly appreciated!  
Thanks!

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [October 21, 2019, 12:04pm UTC](https://forum.wixstudio.com/t/search-dataset/40738/2 "2019-10-21T12:04:31Z")

</div>

Stevie,

With a couple adjustments, you should be close to having what you want. Use “get” only when you are searching in a collection for a particular ID. Instead, use “query”, and it will allow you to refine the search using one of the functions. For this purpose, the startsWith function would be better.

```javascript
 export function input1_keyPress(event) { 
 // Runs a query on the "TablePlan" collection  
 wixData.query("TablePlan")    
  .startsWith("Surname", $w("#input1").value)  
  .find() // Run the query  
  .then(res => { // Set the table data to be the results of the query       
   $w("#table1").rows = res.items;  
  }); 
 }

```

---

<div class="post-metadata">

**Author:** ![steviecain](https://avatars.discourse-cdn.com/v4/letter/s/dec6dc/32.png) [@steviecain](https://forum.wixstudio.com/u/steviecain)\
**Post date:** [October 21, 2019, 11:52pm UTC](https://forum.wixstudio.com/t/search-dataset/40738/3 "2019-10-21T23:52:07Z")

</div>

@tony-brunsman - Legend thank you - that worked with that tweak!

Hugely appreciated!

![](https://us1.discourse-cdn.com/wix/original/3X/1/5/15b642010773d06923b1563d42759b2fbfbcd11e.gif)
