Organization structure - Display Employees under a CEO

Hi. Hope you’re doing good.
I have a question because I need to display info of all the employees under the CEO of the company.
So under the CEO, there are managers, and under those manager, there are other managers, then we get the employees, so the info is recursive. I’m wondering how Can I display the info of all employees under a given manager who can have another manager under him.
I have a table Employees that have a field called Manager (which is an Employee Type itself), this field stores the manager of the employee…
Thanks

Use repeating groups to display parent and child data.
Parent Repeating group will have one column. Do not restrict columns for child repeating groups. It 8a up to you how you would like to design it. But try using groups inside repeating groups to display data.

So lets assume you’ve got a type of thing in your db called employee

A simple example:

Lets say you have the following company hierarchy

  • Julie Smith - CEO
    • Joe Johnson - VP
    • Alejandro Piper - CFO
      • Devon Pierce - Head of Accounting

you can form a basic hierarchy where each employee thing might have the field of employee ‘name’, ‘title’, and ‘boss’

Database Example things

Thing 1
name (text) Julie Smith
title (text) CEO
boss (custom type: employee) [empty]

Thing 2
name (text) Joe Johnson
title (text) Vice President
boss (custom type: employee) Julie Smith

Thing 3
name (text) Alejandro Piper
title (text) CFO
boss (custom type: employee) Julie Smith

Thing 4
name (text) Devon Pierce
title (text) Head of accounting
boss (custom type: employee) Alejandro Piper

You can see each of these things together form the basis for a simple hierarchy where the boss points to the employee above in the hierarchy

Step 1

Create a repeating group of type employees on the page.

Use the following expression as your data source

do a search for employees

boss : is empty

This should return the top employee in the hierarchy (the CEO) who has no boss specified in their db thing

Step 2

Nest another repeating group inside a the repeating group you just created.
-Data source type employee
-Expression do a search for employees

boss : current cell’s employee

Step 3

Repeat adding a 3rd, 4th, etc nesting repeating groups, each inside the other, with the same dynamic expression.

Although you can theoretically create an hierarchy of unlimited depth within the db, when designing your UI in bubble you’ll need to design in exactly how many hierarchy levels you’ll want to be able to display on the page by how many RGs you nest. Bubble’s UI doesn’t have a way to natively display ‘n-depth’ db searches (yet)

Other Notes

Keep in mind, you don’t need to put the top level employee (the CEO) in a RG, but I’m trying to show off the recursive way of accomplishing this using the current cell’s employee dynamic value thats available inside a repeating group cell. You can simply use this expression over and over for each nested level.

This db structure I’ve exampled here is a very, very simple one. It certainly isn’t ideal for every use case. Your app may struggle to use this design at scale and depending on the size/complexity of your employee hierarchy.

  • You may find that using a separate ‘carrier type’ to store the hierarchy relationships between your employees (bosses and subordinates) things is best for flexibility.
  • You may find that storing a list of subordinate employees inside each employee will be fastest to load. There can be some complexity to change the hierarchy and keep things consistent using this method

Hello Jon2
Thanks for the reply and the effort, I appreciate.
Yes, but the problem with this method is it will become messy very fast. I mean having repeating groups in other repeating groups and so on is not very clever. I taught it was another way to do that but you mentioned that “Bubble’s UI doesn’t have a way to natively display ‘n-depth’ db searches (yet)”. that sucks. I was wondering if we can use queries that I can write myself to do that but anyway.
Thanks mate. Will continue digging.

Cleaver it may not be, but this is absolutely the vanilla way to accomplish this in bubble. Someone told me this and I didn’t listen–assuming I could just muddle through–which was a mistake in retrospect. If this is core feature to your app, think seriously about how you want to accomplish this now. Maybe there is a plugin that will do this or you could have someone write something for you that generates some HTML. Even though it might offend your sensibilities, you might just decide that building out a N level depth of nested RGs is just the best, down-and-dirty way to get to the end.

Recursion and loops are honestly one of the most challenging ‘gotchas’ in learning the platform. Intuition says that it should be simple to do anything N times when building software, but that’s just not the case–at least without using some kind of plugin, etc. Bubble will return a list via an RG, but any sub RGs must be statically specified. The visual editor is lets you draw a certain number of elements, you can hide/show, but they are ultimately predefined and fixed. You can’t have bubble, for example, spawn another sub RG and that RG spawn another. It may seem like it ‘should’ work that way but it absolutely does not.