The table's last column (action) contains pc.button, that can get data in the row that the button residing in, and then send that data to a State variable.
Some thing like this:
| name | age | job | action |
|---|---|---|---|
| John | 20 | Developer | Update |
| May | 23 | Designer | Update |
I have tried pc.list like this:
return pc.center(
pc.list([
["name","age","job","action"],
["John",20, "Developer", pc.button("Update", on_click=State.update_employee)],
["May",23, "Designer", pc.button("Update", on_click=State.update_employee)],
])
)
but pc.list can only take in python primitive types (str,int,float...). Is there any way to add multiple components progamatically to another Pynecone component
https://youtube.com/shorts/u-TUSQ9DkCw <-- Example here I write the following full example for what you want.
The simple answer is to use table_container. But we need to care about some detail.
(1) You need to define a class. In my case, it is
Member(pc.Model, table=True).You must add
(pc.Model, table=True)Can we use [list[list[str]] to represent the self.members?
The answer is NO.
That's we we use
members:list[Member]in State but notmembers:list[list[str]].(2) When your code satisfies the above condition 1, then we can
use pc.foreach() to generate table's data in UI.