Repeating Group - filter by field on another (related) table?

Hi there,

I’m trying to filter the results of a repeating group by a field on another table that is related to a player. Specifically, I have a repeating group of players, and users can select one or more positions to only show players that play those positions. I have a custom state ‘filter_position’ (type option set: Position (Rugby Union) that stores a list of filter selections.

I have two data types - Player and Player Profile (Rugby Union). The Player data type has a profile_rugby_union field of type Player Profile (Rugby Union) which holds the unique ID for their profile.

The reason I have designed it this way is so that my Player data type doesn’t become monstrous, and makes the app easier to extend in the future. There are a number of ‘Player Profile’ data types for different sports that someone may play.

My repeating group of Players.

I thought this would be as easy as adding a constraint to the repeating group’s data source ‘search for players’ that said Player’s profile_rugby_union’s position = one of the items in my ‘filter_position’ custom state list.

I have no problem accessing the Player Profile (Rugby Union) related to the player to show their position in a text field in the repeating group, e.g:

Screen Shot 2023-01-06 at 9.30.39 pm

Not sure why this is so difficult - appreciate any help! :slight_smile:

Hi there, @thethinklab.au… if I understand your post correctly, you need to use an advanced filter in this case because you don’t have a direct relation between the repeating group’s data type and the field on which you are trying to filter.

The above being said, add the :filtered operator to the end of your repeating group’s data source. Then, add a constraint to the filter, scroll to the bottom of the constraint dropdown, and select the Advanced option. At that point, you should be able to construct the desired expression.

Also, if you have never used an advanced filter before, be aware that the filter happens on the client (browser) side. So, the search is going to return all of the relevant items to the client, and then the filter will be applied. As you can imagine, there might be a performance impact if a lot of items are returned in the search. Anyway, just something to keep in mind.

Hope this helps.

Best…
Mike

3 Likes

+1 to Everything Mike has said.

Advanced filter is what you want (no idea why Bubble hides it away). Just make sure you have done as much pre-filtering as you can (which I think you have with the Club filter) to ensure the client side filtering is performant.

Only really here for the “Hooker” lols :rofl:

(ex scrum half here).

3 Likes

That’s a design trade-off decision you have to make working with the Bubble database.

The choice between overloading your Player data type with attributes like “position” vs making your searches and UI more complex.

It’s enticing to think of the future extensibility to other sports, but with it will come performance issues with Client side filtering.

No black and white answers … or all answers are right :slight_smile:

3 Likes

Thanks @mikeloc

I’ve progressed but am still a little stuck. If I select the filter, players in the associated club with the selected position will appear, however, 0 players appear on page load.

I want the default behaviour on page load to be that all results are displayed, which are then narrowed down if a user selects positions - I thought selecting ‘Ignore empty constraints’ might achieve this but it hasn’t…

Following is how I have constructed the search, constraints and advanced filter:

Screen Shot 2023-01-07 at 6.55.55 am
Screen Shot 2023-01-07 at 6.55.48 am
Screen Shot 2023-01-07 at 6.54.58 am

I’m not necessarily following all of the details there, but at a higher level, ignore empty constraints doesn’t work with advanced filters. So, instead of using that setting, you would have to conditionally change the repeating group’s data source based on whether or not any positions have been selected.

Ok that explains it! Would the optimal way to do this be on a workflow attached to each filter button i.e

button is selected - redo search with filter
button is deleselfted - redo search without that filter

?

There are multiple ways to do it, and sure, that way is fine.

1 Like

For my own knowledge, what other ways are there?

Which way would be best performance/security/experience etc