How to filter repeater

I’ve got a database of items which is sorted by Resources, Reports and Projects. Some are current, and others are “archived” - which I’ve set up with a Boolean field that’s “true” if the item is archived.

I have two separate repeaters (on two separate pages) for users to look up current items and past items - which is filtered using the manage Dataset menu to filter between archived (true) and not archived (false) pages.

I have a drop-down field for them to choose the sort by type (resource, report or project). The sort works fine with the onChange function, but the problem is that the original filter on the Dataset that says if it shows archived items or not gets wiped out.

Is there a way to set the code so that I keep that first filter applied, but add in the filter for the type once someone chooses it in the drop-down?

Thanks!

 
export function selection_change(event, $w) {
    $w("#dynamicDataset").setFilter(wixData.filter()
    .eq("type", $w("#selection").value))
    }

Hi Wanda!

I need the full code you use (and a link to your site may help me provide you with better solution),
but as for now, the code you posted lacks a few things. Read this API reference about filtering data.

Your code should look something like that:

export function selection_change(event, $w) { 
     $w("#dynamicDataset").setFilter(wixData.filter() 
     .eq("type", $w("#selection").value))  
     .find()
     .then( (res) => {
         let filteredData = res.items;
         $w("#myRepeater").data = filteredData;
      })
     .catch( (err) => {
             let errorMsg = err; 
      });
}

You can also check these previous forum posts on the same subject:

Hope it helps.
Best of luck!

Doron. :slight_smile:

Hi Doron,

Thanks for the assistance. I managed to get the code working another way.

Wanda

Hi Wanda,

I am attempting to create a filter for my repeater as well. Can you please explain how you managed to get your code to work? I’ve made a post about this but have yet to receive a response and really need to get this figured out. Any feedback would be greatly appreciated.

Kind regards,
Brittani