How to Set a Custom State with Only the First Subcategory from Each Main Category?

I’m trying to create a custom state in Bubble.io that stores only the first subcategory from each main category in a store. This state will control the visibility and styling of buttons.

Database Structure:

  • Store (e.g., Supermarket)
    * Main Categories (list)
    * Subcategories (list)

Supermarket
├─ Frozen (Category)
│ ├─ Pies (Subcategory)
│ └─ Ice-cream (Subcategory)
└─ Beverages (Category)
├─ Juice (Subcategory)
└─ Soft drinks (Subcategory)

The custom state should contain only the first subcategory from each main category:

  • ["Pies", "Juice"]

Below you can you an image of what I’d like to do.

As pointed with the red arrow, I’d like to do the same with the subcategory “Pies” pointed out with the yellow arrow.

Thanks for you help in advance.

Assuming you have:

  • Store{ name, categories(list)};
  • Categories{ name, subcategories(list)}; and
  • Subcategories{ name}.

You can then setup a repeating group with type categories and get the first subcategory from each category.

Similar to this: Example

1 Like

Hey, thanks for replying. It helped a little, this info is exactly what I want, but I couldn’t apply the same logic to get that on a Custom State. Not sure if there is a way to do that or I’m missing something in the way.

Have you faced anything similar?

( To be clearer, I’d like to have a list of all first subcategories of all categories. They will be visible as soon as the page is loaded. The information given in the repeating group is exactly what I want, but I couldn’t put it in a custom state )

Thanks again for you time.

I think you should create two data types -

  1. For Category only

  2. For Subcategory only and then Map it with Category while adding subcategories.

This way you’ll have more control towards custom states and have robust filter abilities. While creating a custom state make sure you map it with subcategory with datatype subcategory, and it should not be a list. Everytime you fetch subcategory from the RG, it will only fetch data for :firstitem

1 Like

Let’s say you have Categories A, B, C and each has 2 subcategories 1,2,3,4,5,6 respectively. When you search for categories each items subcategories first item, you expect the list you want in this case [1,3,5], however, what is happening is is that all subcategories will be appended first resulting in [1,2,3,4,5,6] and then the first item will be returned, resulting in [1].

1 Like

Can you please record a loom and share?

1 Like

My data types are already organized like that. I’ll check if your tip works and return with a feedback. I appreciate your time.

1 Like

Hey,

I’ll sleep on it and I’ll let you know. Thank you!

Will do

Hello,

I’m sorry for the late reply.

I tried to be as clear as possible. Let me know if you need any more information.

Thank you again.

No problem, thanks for reaching out. Can you give access as a collaborator where I can do changes and fixed the issue for you? This would be paid, and I charge $30 hourly. I would charge for 2-3 hours max.

You can hire me through Upwork as well if you want to - https://www.upwork.com/freelancers/~012b8876722cf4a269

Looking forward to resolve this for you.

This topic was automatically closed after 70 days. New replies are no longer allowed.