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’ .