Hi
I am trying to build a datagrid where the number and types of columns are know only at runtime, because they’re fetched from DB.
So, the DG is built completely from code following these instructions.
I was able to build each row by adding single DataRowPanels in either way:
- “simple way”: that is, just setting the item property of the DRP, with the drawback that data is displayed only as labels (see code of
button_1_click
) - “complex way”: that is by adding components for each column 1 by 1, so to allow more flexibility on data display (see code of
button_2_click
)
But I really seem unable to figure out how I could do the same setting up a RepeatingPanel and assigning a DataRowPanel as item_template at runtime.
I’ve tried (see code of button_3_click
) but couldn’t get over these 2 questions:
- when assigning the RP’s
items
property to a list of dictionaries, I get the errorTypeError: '<invalid type>' object is not callable
- how could I hook up the Delete Button for each row?
See the GIF for better understanding.
Here’s a clone link:
https://anvil.works/build#clone:4RF24TBSNIRCZIBB=6HVB56OUZCKUQGE7BXVJQ2NJ
In the clone I’ve tried to make things simpler by accessing tables from the client, and I am building data rows in a horrible way, and the code is written in a try-to-be-just-clear-not-too-pythonic mood, but that’s not the point.
The focus is on the three button_x_click event handlers and the way the DataGrid (and its components) are built at runtime.
I think this can be istructive for any Anvil noob like me, since it’s about understanding Anvil’s “foundation objects” like data grids, data rowpanels and repeating panels.
Thanks for any help.