Getting data using parent-child relationship [recursive tree]

I’m working on functionality for generating a hierarchy of departments in a company. The departments are set up in the data model with their name and parent (pointing to itself), and other properties.

The app needs to be able to retrieve all childs related to the user’s current position hierarchy (the current parent), as well as the childs’ childs and the childs of that child. As the department could have n numbers of levels (see sketch), creating one object class source per level is not a solution.

Note that we shouldn’t be loading data not related to the current department level, so setting a property with the level of the department and filtering in only data with level > current department’s level doesn’t give the wanted result.

Does it exist any solution for filtering data when setting the object class source using conditions, or does it need to be coded? I haven’t tried to set a runtime property with function type yet, but are unsure if that could be a solution.

1 Like

Could you do a recursive read of objects using a while loop?

image

This setup will read your current department into the list of children to traverse and then “pop it” from the data source, read its children which are added to the list of children to traverse and so on until there are no more children to traverse.

All read departments are added to a separate result data source that contains all children connected to your department.

Hi!

We just updated our documentation regarding the creation of recursive user interfaces (when you have recursive data structures, such as Department.Parent Department)

https://showroom.appfarm.app/use-cases/recursive-tree

2 Likes

If you can build a count as a runtime attribute of which level it is at and then a UI sorting based on that level through margin databinding or something similar?

Interested in the solution here. Have only previously built fixed hierarchies of the same data source!

A feature request here is to make it more visible as an option. I see how its done but still cant get the Tree/Recursive variant to show heh :sweat_smile:

Ah, as noted in the documentation (link above) - recursive tree is currently feature flagged, meaning we need to enable it for your solution! So you may DM me the name of the solution :wink:

Inside the iterating UI, you have access to the iteration level, for usage in e.g. conditional styles or offset calculation

Sorry for not reading thoroughly! It is not relevant at this time, have just bordered it in multiple cases so was curious to know. Nice tip about the iteration level, have not used that before :slight_smile:

Hi, Kristian

I apologize for interrupting this conversation, but I cannot find any documentation note stating that the “recursive tree” iteration variant is currently feature flagged. Can you please confirm if it is still flagged?

I have created a parent-child relationships within the same Object Class, but are not seeing “Tree / Recursive” as a option.

image

Hi!

You are correct, the feature flag is removed in the upcoming release (ETA end of next week), and the docs has been updated accordingly - but that docs change has been merged inn too soon by a mistake. So, hold your horses a week+ more, and it will be available to everyone.

1 Like