How to Make a Cascading List

So I need to make a dependent cascading list that can have a dynamic number of items and levels per item. I attempted to make two identical templates each containing a repeating panel and a link, but as you can see below, a template can’t be nested inside itself.

The other idea I have to solve this is to have a whole pile of CascadeTemplateX’s that are way more than I could (hopefully) ever need, and they just trickle down the line, but that seems horribly inefficient and bloated. Beyond that, I think that the only alternative would be custom JS and HTML, which I’m not well versed in. I’ll certainly do that if it’s the only way, but I wanted to see if there are any thoughts on how this situation might be easily resolved using Anvil’s provided material.

The only thing that prevents you from repeating a form inside itself is the designer. If you’re willing to do it from code, you can do it yourself.
Eg:

self.repeating_panel_1.item_template = CascadeTemplate
self.repeating_panel_1.items = my_child_items

(Or you could just do self.linear_panel_1.add_component() in a loop or something like that, and skip the RepeatingPanel entirely.)

A working example of a similar approach can be found in the “Partner Portal” example, where the administration app has infinite recursion to handle subfolders.

Outlines (hierarchies) are recursively-defined data structures. If the length and depth of each level are fixed in advance, then it becomes possible to manually build it. (In some systems, this requires nominally different types of objects at each level.)

If they’re not known in advance, then you typically need to invent (or discover) two things:

  1. A specification of some kind, in machine-readable form, adequately describing the shape (and content) of the hierarchy in concrete terms.
  2. Program code, to read the specification, and dynamically build the corresponding hierarchy from instances of simpler pieces.

I took a stab at something like this with
Roll-your-own expanding/contracting outlines
You may be able to use some of the same principles and techniques.

There are other examples in the same Forum area. And now that we have ORDER BY in our database arsenal, there may be even better ways to specify the outline structure.

1 Like

I asked the same question some time back. It looks like we have similar problems :slight_smile:

Here is a rough solution. It should be possible to work on it to clean it up, perhaps with some css editing.

2 Likes