Filter content to show all categories

Hello,

Im new to Corvid and web development and I have been struggling to understand why my coding is not working.

I am trying to get my filter to work in terms of displaying items by category. I want to get my code to work to allow it to show ‘all’ categories in the dropdown. Here is my code and the problem I’m facing:

import wixData from ‘wix-data’ ;

export function dropdown1_click(event,$w) {

$w( '#dataset1' ).setFilter(wixData.filter() 

    .contains( "marketField" , $w( '#dropdown1' ).value) 
    .find() 

.then((results) => { 
        console.log( "Dataset is now filtered" ) 
        $w( "#gallery1" ).items = results.items; 
    }). **catch** ((err) => { 
        console.log(err); 

$w( ‘#gallery1’ ).expand();
});
}

Hi Natalie,

You are receiving the parsing error because the code isn’t being closed correctly. This can take a bit of time to get used to if you are new to coding. I know I had issues with it at the start!

You should try your code like this and it will resolve the error.

import wixData from "wix-data"

$w.onReady(function () {

});

export function dropdown1_click(event) {
   $w("#dataset1").setFilter(wixData.filter()
      .contains("marketfield", $w("#dropdown1").value)
      .find()
      .then((results) => {
         console.log("Dataset is now filtered")
         $w("#gallery1").items = results.items;
      }).catch((err) => {
         console.log(err);
         $w("#gallery1").expand();
      })
   )
}

If you have any other issues setting up your filter function you should check out this tutorial we have for setting up a search function for database collections. There is a section that shows how to set up a filter with dropdown menus.

Corvid Tutorial: Adding Collection Data Search Functionality

Hope this helps!

Dara | Corvid Team

Thank you so much this worked!! :blush: