Filter Repeating Group By Any Value, In Any Field

This seems to be a common pain point in instances where you want to filter an RG by specific values in multiple fields.

e.g. Filter by: email is empty, or email is not empty, or address is empty, or address is not empty, or…

It gets quite messy when the number of conditions on an element exceeds 4-5. This option is a little bit more work upfront, but the result is much cleaner and more modular, needing only one conditional expression.

TL:DR

Editor

Preview

tinywow_tinywow_Screen Recording 2023-08-18 at 11.01.34_31993846_31994267

  • Create an option group called “Etablissement Field” for the fields, a simple list of texts:

  • Now create a page level state called “Filter Fields”, a list of texts. On page load, set “Filter Fields” to “search for Etablissement:formatted as text:split by (,)”

  • Within the formatted text you need the Id + booleans for “each field is not empty:formatted as text”. I’m using pipes to delimit the list for easy, safe-ish splitting:

  • Within each boolean, Yes = Has Address, No = No Address and so on (exactly matching the option group texts made previously):

  • Create another page state called “Displayed Field” of type “Etablissement Field” (the option group), default being “All”

  • Create a repeating group, using the option group displays to create buttons. When those buttons are pressed, set the “Displayed Field” state to “Current Cell’s Etablissement Field”:

  • Now on your main repeating group, the default data source can be a search for all, then you simply need to add one conditional expression for when “Displayed Field is not All”. The search constraint checks if “Filter Fields:filtered (to see if they contain the page’s Displayed Field)” contains each Etablissement’s unique Id:

Constraint filter content, to get “Filter Fields” that contain the “Displayed Field”:
Screenshot 2023-08-18 at 10.51.28

Formatted As Text content, to get the unique Id from our list of texts (Filter Fields):

The result:
A pretty modular filter function, where adding new fields to filter by is a simple matter of creating the field on the datatype, then adding more entries to the option group. There are some minor visual glitches that could be pretty easily resolved were this for an actual project, so not a huge caveat.

Why not just put the constraints on the search and check the box for ignore empty?

3 Likes

In an instance when there are 3 or more values in a field, the above would allow you to quite easily search them, whereas the binary ignore null constraints wouldn’t, I don’t think?

Out of interest, how exactly would I go about structuring that were they only binary values? This may well be a bit of a hole in my knowledge, but I can’t figure out how you’d show “No Email” only or “Has Address” only without making multiple conditional searches, which would then land you back at square one on a datatype with many fields.

Regardless, I’ve made a couple of quick changes to the preview to illustrate the point, with the option group for employee count added. I’ve also tweaked it to allow for multiple fields to be used in the top search, then combined with the employee count.

As per my initial point, it’s a bit more work upfront so maybe not worthwhile on a small datatype, but for large datatypes with a dynamic, ever increasing number of fields, this allows you to achieve quite complex filters mess free.

This uses 4 workflows, 1 conditional expression and 2 option groups.

@boston85719 I think I’m with you, it’s not a feature I’ve used too much. Having a page state for each boolean, then using “is in” for larger arrays seems like it’d do the same job.

Not so much of a tip from me after all! :-1:

Still would make sense though as an approach to deal with the fact that Bubble still has not addressed the fact that the advanced filters doesn’t not ‘ignore empty constraints’. I would say parts of this approach can be used for different reasons.

  1. Advanced Filters: Bubble says it is a ‘known limitation’ which is keyword for “we did not fully think through the function and refuse to update it to be more in line with what a fully realized function would be”; the ‘known limitation’ is that you can not ‘ignore empty constraints’ on advanced filters, and since filtering a list using a field that is a list can only be done via the Advanced Filters, it can be a real pain to get appropriate functionality when using an advanced filter.

I’d say you can simply have a text field that you save with the filter values separated by comma on the data type to achieve something to bypass the limitations imposed by Bubble on Advanced Filters.

  1. Speeding up the filter - Again, using a field that is a text field that you add a list of keywords separated by comma onto the data type. I did this in an app to show the number of results per each filter on the filter side menu (ie: Red (22) Blue (18) to indicate 22 results are Red and 18 are Blue). I took all filter types (color, size, gender etc.) and put them into a single text field separated by comma. Then just looked to determine if the filter value (on left side menu) is contained by the filter text field on the datatype.

That approach sped up the filter dramatically, and my numbers next to the filter value updated faster than the industry leading site I was using as a source of inspiration.

Using text fields in Bubble can help in various situations, so you were definitely onto something here.

2 Likes

Thanks for taking the time @boston85719!
Much appreciated, I completely forgot to respond to this, but have already found your input useful , so thanks a bunch.

1 Like