Could I add component to start instead of end of parent?

What I’m trying to do:
I have a parent component of type CardContentContainer where I nest a stream of child components [C1, C2, …]. A button press adds a new child component into the parent with add_component.

I would like the new component to be added to the top of the column, but I wasn’t able to find any docs that give this as an option.

A workaround that feels icky is to call card_container.clear(), add the newest child component then re generate and add the other child components.

Is there a better Anvil-ian way to do this?

FlowPanel has a way to choose the index where the component is to be added. This solves my problem:

parent=FlowPanel()
...
child = get_next_child()
parent.add_component(child, width='100%', index=0)
3 Likes

Glad you solved this! However, using a FlowPanel with width='100%' isn’t necessary here – every container (and slot) has an index= parameter - you could do this with a LinearPanel, or with your custom container directly.

5 Likes

That is great to know1 Now I can stop removing all my components just to add one in a specific place…

2 Likes

Thanks :slight_smile:

The documentation for the containers only listed index as an option for LinearPanel and FlowPanel, which was why I went with FlowPanel. E.g. Card did not have index as one of the possible keyword arguments Anvil Docs | m3

I assume it’s defined on the base class. Are the keyword args documented somewhere?

1 Like

Yep - it’s on our internal docs-TODO list!

4 Likes