# Dataset filter parameters

**URL:** <https://forum.wixstudio.com/t/dataset-filter-parameters/38606>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [July 15, 2022, 2:09pm UTC](https://forum.wixstudio.com/t/dataset-filter-parameters/38606 "2022-07-15T14:09:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![internationalcovidsu](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/internationalcovidsu/32/30580_2.png) [@internationalcovidsu](https://forum.wixstudio.com/u/internationalcovidsu)\
**Post date:** [July 15, 2022, 2:09pm UTC](https://forum.wixstudio.com/t/dataset-filter-parameters/38606/1 "2022-07-15T14:09:40Z")

</div>

I have a Dataset that I want to allow users to filter based on whether they enter filtering criteria or not. There are 4 types of filtering criteria: ’ **color**', ’ **height**', ’ **width** ’ and ’ **length**'. I therefore need to build a query based on which fields the user fills in, IF he fills them in.

This is my code:

```
    $w ( "#datSearch" ). setFilter ( wixData . filter () 
        . eq ( "color" , $w ( "#txtColor" ). value ) 
        .eq( "height" , $w ( "#txtHeight" ). value ) 
        . eq ( "width" , $w ( "#txtWidth" ). value ) 
        .eq( "length" , $w ( "#txtLength" ). value )) 
        . then ( () => { 
console.log("FILTERED!"); 
    } ) 

```

If the user fills in only one field it works fine. When a user fills in 2 or more fields, it doesn’t work anymore.

**Example:** If the user enters filtering criteria for **color** (say, ‘blue’) and **length** (say, ‘59’), I’d expect the dataset to be filtered for **‘blue’ AND ‘59’**.

---

<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:** [July 16, 2022, 6:23pm UTC](https://forum.wixstudio.com/t/dataset-filter-parameters/38606/2 "2022-07-16T18:23:58Z")

</div>

@internationalcovidsu There is a good example of how to do this in the [documentation for the dataset setFilter function](https://www.wix.com/velo/reference/wix-dataset/dataset/setfilter) . With your code, chaining the filter statements together based on whether the filter criteria is filled in, would go something like this:

```javascript
let filter = wixData.filter();
if ($w("#txtColor").value){
    filter = filter.eq("color",$w("#txtColor").value)
}
if ($w("#txtHeight").value){
    filter = filter.eq("height",$w("#txtHeight").value)
}
if ($w("#txtWidth").value){
    filter = filter.eq("width",$w("#txtWidth").value)
}
if ($w("#txtLength").value){
    filter = filter.eq("length",$w("#txtLength").value)
}
$w("#datSearch").setFilter(filter);

```

---

<div class="post-metadata">

**Author:** ![internationalcovidsu](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/internationalcovidsu/32/30580_2.png) [@internationalcovidsu](https://forum.wixstudio.com/u/internationalcovidsu)\
**Post date:** [July 16, 2022, 9:54pm UTC](https://forum.wixstudio.com/t/dataset-filter-parameters/38606/3 "2022-07-16T21:54:34Z")

</div>

Works! Thanks! 🙂
