Corvid filter code breaks dataset filter.

Hi, I am having an issue as I try to build a gallery on Wix. I have a collection of all my work with fieldtypes to separate then by type, subtype, and subject. I wanted to create three different repeaters using the collection that could be filtered even further on-site using Corvid.

I made three different datasets using filter tool to separate the collection by Type (let’s say the types are Person, Place, Thing). So, I set up a repeater to display all the items under “Person,” and that worked fine.

But I hit a snag when I created filters using corvid to further filter the Person data set by subtype and category. For every Person, Place, and Thing, there are subtypes that sometimes overlap (A, B, and C, we’ll say). When I applied filters to the Person dataset, it started pulling in Places and Things with the same subtype.

Basically, the filters I applied using corvid seem to be canceling out the original filter I applied to the dataset, which is not how I want the page to behave.

If anyone has any idea at all to fix this issue, I’d greatly appreciate your guidance. Thanks so much in advance for any help!

Hey Noelle,
The code you are writing with corvid overwrites the default dataset filters.
The best way to achieve what you are looking for, it’s to use wixData, and not use the dataset at all.
You can find here an example of how to filter With Multiple Options:
https://www.wix.com/corvid/example/filter-with-multiple-options

Best

Binyamin

Aaah, I see. Thanks for that insight.

What I’m confused about is how I apply that initial filter to the dataset on load if I don’t do it through the editor. In the example you sent, the recipes collection loads in full, and then is filtered once the viewer clicks the tags. But I need the initial load to be filtered down to one type, and then the user filters it further.

I’ve created a query I believe is what I need to apply to my collection in the code, I’m just have trouble figuring out where/how I need to execute it in the code so that the collection loads filtered.

function query() {   
    wixData.query("Gallery")
        .contains("type", "person")
        .find()
        .then( (results) => {
            $w("#repeater1").data = results.items;
        });
}

Forgive me if this is a stupid question (I’m a corvid newb), but could you give some insight into how I apply this query to collection when the page loads?

Hey Noelle
There are no stupid questions :slight_smile:
We are here to help and learn from you,
For executing code on page load, the function simply needs to be inside the onReady() function.
Because it can take a sec to execute the code, I recommend hiding the repeater by default, then after implementing the data into the repeater - show the repeater.

I also using async-await for a better understanding of the code, take a look:

import wixData from 'wix-data';

$w.onReady(function () {

    $w("#repeater1").hide();
    initPage();

});

async function initPage() {
 try {

 const queryResults = await wixData.query("Gallery")
            .contains("type", "person")
            .find();

 if (queryResults && queryResults.items.length > 0) {
            $w("#repeater1").data = queryResults.items;
            $w("#repeater1").show();
        }

    } catch (err) {
        console.error('initPage error', err.message);
    }
}