[Answered] Dynamic dataset -> filter reference field

Hi all. First post. Started Wix today for my own site. In future I’ll need to make some addons, but I find most stuff is available, and that brings me to my first question, unknownity.

I see if I add a ‘dataset’ to a page, I can add filters to all columns of a specific type including ‘reference’. Now I made a category page with a ‘dynamic dataset’. This for you can then list stuff with filters. Unfortunately the ‘dynamic dataset’ doesn’t allow filters to ‘reference’ columns. In my case I want to link to a so called ‘category page’ for a specific country code (not multilingual in this case). This is a reference field (the datacollection ‘countries’ is used several times in other ‘datacollections’).

Does someone know if this is possible in some way, add a filter to ‘reference’?

Thanks in advance.

Hi Edgar,

In order to filter by reference fields on a dynamic page, you need to add a second dataset that is connected to the referenced collection. In your case, that would be “Countries.” Then you filter that second dataset by the current item on your page. For more information, see this article.

Hello. Thanks. I can figure it out that way. I just thought I may have missed something. I’ll need to relook at my table structure too, for it will mean specific filtering won’t work via a url. Expample, I won’t be able to put the primary_key, country_code (reference) and language_code (reference) in a url but need to split it.

Yes. Reference fields cannot be used to build dynamic page URLs.

I know this will probably bump you all however I came across this thread whilst trying to do something similar. So putting this here to potential help people.

Code I used then explanation below:

import wixData from 'wix-data';
$w.onReady(function () {
    
    $w('#dataset1').onReady(() => {
        $w("#dropdown1").onChange(() => {
            console.log("Search has been entered")
            $w("#dataset1").getItems(0, 99)
                .then((results) => {
                    for (let result of results.items) {
                        console.log(result.manufacturer)
                        if (result.manufacturer === $w('#dropdown1').value) {
                            console.log(`The Manufacturers have matched. ${$w('#dropdown1').value} was searched and the ID: ${result._id} Has matched it.`)
                            return (
                                $w("#dynamicDataset").setFilter(wixData.filter()
                                    .eq("manufacturer", result._id)
                                )
                            )
                        }
                    }
                })
                .catch((err) => {
                    console.log(err)
                });
        })

    })
});

Formatting doesn’t look great on here but this is effectively what I am doing.

Step one, load in the dataset that you are using as a reference.

Grab the items from said dataset, names, ID’s etc. Then I am pulling the names and pairing it against the dropdown. Once that has matched, I then do a return to stop the looping, returning the filter for the items on the page.

The user will see the user friendly name but on the backend the filter is done by the ID. Hope this helps someone.