A simple dataset filtering

Hi,
I’d like to filter my dataset like this

  1. .eq("a", "b") 
    
  2. .eq("c", "d") 
    
  3. .eq("e", "f")  **OR**  isEmpty("e")  
    

The results must match to conditions 1 AND 2 AND 3

How can I do it?
I’ve read this one https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#or but it’s not the same.
Thanks in advance,
J.D.

#setFilter, #filter, #and(), #or(), #dataset

1 Like

Hi,

I just tested this and it should work, just change it accordingly to filter a dataset

wixData.query("myCollection")
  .eq("a", "b")
  .eq("c", "d")
  .eq("e", "f")
  .or(
    wixData.query("myCollection")
       .eq("a", "b")
       .eq("c", "d") 
       .isEmpty("e")
  )
  .find()
  .then( (results) => {
      //do cool stuff here
  });

[UPDATED] For filtering dataset (tested)

export function button1_click(event) {
    $w("#dataset1").setFilter( wixData.filter()
        .eq("a", "b")
        .eq("c", "d")
        .eq("e", "f")
        .or(
            wixData.filter()
            .eq("a", "b")
            .eq("c", "d") 
            .isEmpty("e")
        )
    )
    .then( () => {
        console.log('Done');
    });
}

Thank you, Shan,
Meanwhile, I did it a little bit differently, and it seems to work, but your way looks more straightforward. I’ll try to apply it next time :slight_smile:

Thanks again,
J.D.