Solved Adding components to Interface dynamically after onInit()
Hey, I am working on a feature where you can list all samples that are located on your hard drive.
I want to add a new panel for every file (sample) the user has installed, however these samples will be served by an API so the samples are not known
I am getting this error:
Tried to add a component after onInit()
One possible solution I was thinking off was adding all the necessary panels on the
onInit()and just render them empty. Then once they are needed I can fill them with the sample names. I could also add pagination if needed, however I was wondering if there is a better solution for my problem? I will also need to register callback listeners for mouse events for each panel.
Is there a good solution to dynamically add panels?
The only controls that can be added outside of on init are child panels.
A better solution is probably just to have one panel and make its content dynamic.
@d-healey Thanks for the help! Really appreciate that. I will be using child panels.
When using only one Panel with dynamic content I would need to deal with getting the click position, mapping that to a file name also stuff like hover states get more tedious. In terms of performance wise however one panel would be better but since I am not rendering anything other than that file browser it should be fine.
@oskarsh Try using a viewport in table mode, this is exactly the intended use case for it.
Start reading here:
@Christoph-Hart Amazing exactly what I was looking for, much cleaner than handling all the child panels! Thank you.
I've created a snippet for everyone who is interested using some minor custom LAF.