Filter a List Difficulty

I have a situation that I cannot figure out how to do without traditional code. I know Javascript and could write a function using Toolbox, but I do not want to use a workflow. I am using this particular filtered list as the Data Source for a Repeating Group.

Here is the issue:

Lets say I have a list A with the following values:

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Some of these items might, or might not, belong to a group (indicated by a field on the Thing).

If I want to display the first five items of A, this is easy:

[1, 2, 3, 4, 5]

But if any of these belong to a group, I need to display the entire group.

  1. The group counts a one item to display, but must show all group items
  2. It is unknown how many items belong to a group

So, for example, if I have Group B [2, 3] and Group C [5, 6, 7], then my filtered list must be:

[1, 2, 3, 4, 5, 6, 7, 8]

Item 1: 1
Item 2: [2, 3]
Item 3: 4
Item 4: [5, 6, 7]
Item 5: 8

It’s possible there would be a group of items that should not be included. For example, if Group D is [11, 12, 13] and List A is [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], I still need only items until #8 to list the first five.

Because I want to use this filtered list as a data source that must remain dynamic, how can I arrive at this filtered list and know that I need to use A:items until #8 in order to show my first 5 items?

One method I wanted to try was to save the number of items in a group in a field for the group (it is a data type, so I could create that field and keep the count current). But I’m still not sure how I would construct my list filter even if I know that information.

Any help is appreciated! Thanks.

This was a nice little puzzle. So, the approach I took was to manipulate the RG design.

The filtered RG is a list of items that either:

  • Have no group
  • or are the first of a group

Inside the RG cell are 2 possible visual elements that only display under one of the following conditions:

  • If cell’s item is not grouped > show the name of the ungrouped item
  • If cell’s item is the first of a group > show a nested RG of items that in the same group

Here’s my demo editor: coaching-sandbox | Bubble Editor

Here’s the preview (feel free to re-assign groups with the dropdown to see how the filtered list changes): https://coaching-sandbox.bubbleapps.io/version-test/list-filter?debug_mode=true

Pay attention to the source of “RG Filtered List” as well as the conditions of the two inner elements. I put a star icon next to these to make them easier to find.

I used another RG (on the left) to do the main search of all items. This is helpful to cut down on overall searches and is referenced a few times in the filtered logic/conditions.

Cheers,
Gaby
Coaching No Code Apps

Hi Gaby! Thank you for taking a stab at this problem. :slight_smile:

I left out a lot of specifics to try and focus on the main problem. I actually already have a nested repeating group similar to what you describe. My first attempt was to just show one row of the nested group if the item is not in a group, or to show X rows when there is a group. So I’m thinking along the same lines.

I got tripped up on knowing how many items to pull from the unfiltered list so I end up with the right amount of items. I can’t know how many items to count for each one so that I know when I’ve reached the desired goal without some sort of loop like a traditional function. At least that’s how I keep thinking of it.

I’ll check out your solution soon. For the short term, I decided to simplify my solution to only show a group if it is the first group and it appears in the first 5 items. So if [3, 4] are a group I might end up with only 4 Things:

1: 1
2: 2
3: [3, 4]
4: 5

or with [5, ,6, 7] I might have 5 Things:

1: 1
2: 2
3: 3
4: 4
5: [5, 6, 7]

Both examples only show one group.

This would result because initially I’m only looking at the first five items, but if there is a group, I’ll pull the whole group, so I might have fewer than 5 things (1st example) or 5 things with the extra rows needed (2nd example).

I’ll circle back later and include the full solution. I appreciate the input.

By the way, I finally launched my app! It’s currently in beta and has come a long way since I finished your program. Although it has taken me a long time to get this out, it’s a lot more complete and polished than it would have been had I released it last year. (I know I shouldn’t worry about polish, but I know my market and it will not tolerate substandard apps, even in beta…) Your program was an amazing jump start to the process though and really helped me to progress quickly in many ways. I hope you’ll take a look. I’m quite proud of how it turned out! :wink:

Yeah, check out my solution because it is dynamically responding to the groupings to show 5 “things” every time, whether it’s an individual item or a grouping of multiple items. I think it’s what you’re looking for, but happy to bounce other ideas around if there’s something still missing.

Congrats on the launch!! :rocket::tada::clap: We’re super proud of you :flexed_biceps::grin: