Filter a collection by two relations

I’d like to display a list of car dealerships, filtered by both city and car brand.
However, instead of having one list of all the dealerships with two filters on the page, I’d like the user experience to be:

  1. Select your city from a list
  2. Select a branch from a list
  3. See all dealerships for that brand in your city

So I have 3 tables. Both “City” and “Brand” only have a “Name” column.
Then the “Dealership” table has a “Name”, “City” and “Brand”.

What I have so far:

  1. Screen with a collection of cities
  2. City detail screen shows a collection of all brands (not filtered)
  3. Brand detail screen shows a collection dealerships filtered by the brand

I’d like to be able to filter the 3rd screen by the city that was initially chosen, but I can’t seem to find a way to pass this value from screen 1 to screen 3.

I’ve seen a bunch of posts around about “Inline lists” that you can use on the detail page to filter by a relation. But I can’t seem to find them anywhere. My dealership collection is a regular list using a screen value to filter by brand.

I’ve also seen people creating multi filters by making a filter set a column on the user table. But I can’t figure out how to do this when you click an item in a collection.

Is there a way to do this? Or is perhaps my data shaped incorrectly to allow this?

That’s probably the simplest way to do what you want.
You just modify the Item Click Action on the Cities collection so that it first sets the selected City Name in a column in the User Profile Row, and then does a Show Detail Screen → This Item. Then when you get to the Dealership screen, use that value as a filter.

To modify the Item Click action, you need to enable advanced actions, and then create a custom action for Item Click.

Note that the above will only work if you have User Profiles configured, and will only work for Signed In Users. If you have Users that won’t be signed in (ie. Visitors), then you’ll need a different solution.

1 Like

Thanks for the quick response Darren, it works perfectly!

Out of curiosity, how would you handle this with visitors?

If you had a mix of Visitors and Signed In Users, then I would recommend using a single row Helper table.

  • Create a table and add a single row
  • Add a User Specific Text column
  • Create a screen with a custom layout that uses this table as the source
  • Add a Collection and set the source as the Cities table
  • Modify the default Item Click action so that it first sets the City name in the User Specific column
  • In the Dealership table, add a Single Value column that targets the User Specific column in the Helper table. That will apply the selected City to all rows in the Dealership table.
  • Use the Single Value column as a filter.
1 Like

Great idea, thanks Darren.

How would you go about showing some sort of empty state if there are no items in the collection which match both the filters? Ideally I’d like to show a message that contains the selected items, eg. “Sorry, there are no Ford dealerships in Brisbane”. But a generic message would be fine too, eg. “Sorry, there are no dealerships here”.

Once you start having multiple filter conditions and cases it’s usually best to move the logic to the Data Editor.

Can you show me what you currently have in terms of filtering? (how it’s configured on your final collection)

We are inside a “Brand” and the it shows a collection of “Dealerships” based on the relation from “Dealership → Brand”:

Then there’s an additional filter where “Dealership → City = User → Chosen City”

But when there are no “Dealerships” that have both the current “Brand” and the User’s “Chosen City”, then it just shows a blank page.

Okay.

What you can probably do here is change that relation column to a query column, and set two filters on it:

  • Brand is This Row → Brand
  • City is User Profile → Selected City

Use that query as the source of your Collection (without any filter), then add another component with the message you want to show, and set the visibility on that so that its only shown when the Query is empty.

2 Likes

Thanks for your help Darren, it’s working perfectly!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.