Hi!
i want to see updates in my table, when objects are updated.
How to implement this? How to tell the table to “reload” the elements.
The Text-Field shows the updates.
Looks like reflex somewhere looses the connection/reference between the objects. Is this related to the table of rx.Model?
import reflex as rx
from rxconfig import config
class simplePart(rx.Model, table=True):
def __init__(self, desc="", price=0):
self.desc=desc
self.price=price
rx.Model.__init__(self)
desc: str
price: float
class State(rx.State):
debug: str="dbg"
parts: list[simplePart] = []
#sp1=SpendPart("desc1", 500.1)
sp1=simplePart()
sp1.desc="desc1"
sp1.price=1.11
sp2=simplePart()
sp2.desc="desc2"
sp2.price=2.22
parts.append(sp1)
parts.append(sp2)
def updatepart1(self):
self.sp1.price+=20
self.debug+="upd"
def parts_row(part: simplePart):
return rx.table.row(
rx.table.cell(
part.id
),
rx.table.cell(
part.desc
),
rx.table.cell(
part.price
),
)
def parts_table():
return (
rx.table.root(
rx.table.body(
rx.foreach(
# State.UpdateSelectedParts(), parts_spend3
State.parts, parts_row
),
),
),
)
def index() -> rx.Component:
return rx.container(
rx.text(f"debug: {State.debug}"),
rx.text(State.sp1.price),
parts_table(),
rx.button(
"UpdatePart1",
on_click=State.updatepart1,
)
)
app = rx.App()
app.add_page(index)
Greets from Bavaria, Freisei