Filtering by Reference Fields

Hello,
I really like the reference fields we can set up between data collections. This helps a LOT!

However, I am unable to filter by or sort by reference fields. My only workaround right now is to create a separate field, and manually type in the reference field data.

Is there something I’m missing about how to filter by or sort by reference fields? If not, is it possible to add this as a feature?

Thank you

2 Likes

Hi Sean,
You can use the query function of the Wix Data API to check which reference field equals to the relevant value.

Have a good day,
Tal.

Hi Tal,

I’m actually talking about when I add a dataset to a page, and I can add a filter.

I;
Click + Add Filter
In the Add Filter dialog box, for Field I click Choose, and the Reference fields do not show up.

Are you saying that i can use Query to have the Reference fields show up in the Add Filter dialog box?

HI! Sort by reference in’t supported yet. Filter by reference example you can find here CMS: About Displaying Content from Multiple Database Collections Using Reference Fields | Help Center | Wix.com

Do you know when sorting by reference field (either in the database/spreadsheet view, OR from the dataset, OR from the front-end side by the user) will be available?

Hi Sean,

Unfortunately we are not able to provide an ETA.

Feel free to post your request in our Feature Request forum

Hi guys, to filter by a field in a collection that is connected by a reference to another collection…

I kept trying to filter using the text values displayed in the reference field; which of course came from a list populated from another collection i linked it to. But as mentioned this did not work as it does when using fields found directly in your main collection being used for the dynamic page.

Turns out that when wix connects a field via a reference to another collection, even though it does display the value using the Text Label, it actually assigns some sort of weird alphanumeric id to it. If you make a field a reference field, choose values for some items in the referenced database collection, then turn the field back into a text type, it will display this code id! It will warn you you’re breaking connections when you do, but When i used this as the value, voila, my dropdown filter worked! I just turned that field back into a reference type and i could still choose values prepopulated from my referenced dataset.

I am having this exact same issue. Do you have to flip back and forth from a reference to a text field every time you add data to the collection?

Please add your site to review.

@olesiaz Yisrael is looking into the issue. Thank you for the reply!

I’m getting the same issue, do you have to base a query off of the alpha numeric value generated from the referenced field, or is there any additional guidance here yet?

Thanks

I was helped in this thread.

Hope that helps with what you need

That worked for me. References use the ID field of the row in the parent database, instead of the field containing the string value we see on the UI. The ID field is originally hidden, so first I had to make to edit the parent database to make it visible. Then I filtered the child database by matching the reference field with the ID field of the parent. It can be accessed using the key “_id”. The code runs something like this:

wixData.query(“ParentDB”)
.eq(“parentfield”, selectedValue)
.find()
.then( (results) => {
if (results.items.length > 0) {
let firstItem = results.items[0]; //see item below
selectedKey = firstItem._id;
// filter
$w(“#dataset1”).setFilter(wixData.filter()
.eq(“childfield”, selectedKey));
}
});

Where ParentDB is the parent database (the one containing the parentfield that the child DB refers to), and childfield is the field in the child database that refers to parentfield.

?

hi guys, is that possible to make a input search bar for repeaters that search for the reference field when people type, instead of normal fields like “title”.

I have this data im using as reference field in my principal data. this reference field has items like “wooden” and “iron”. So if i have “tables, chairs, blocks” etc. that are made from wood, i have put the “wooden” option in the relative reference field. now i just want my searchbar to find everything made of wood by typing “wooden”. however when i set the code to search there, it gets blank results in my repeater, not showing at all. Is it possible to do?

Did you manage to get a solution for this. I am in a similar kind of situation.

@tdperez Wow this a think-outiside-the-box genius answer