[Question] How can I access the text value of a DataTable Cell with the on_tap event? #5270
-
QuestionI have a datatable that I'm generating dynamically based on JSON returned from an API. I later want to be able to tap / click on a cell, and use the value from that cell to call a subsequent api endpoint to bring back details for that value specifically. I can't get any value from the on_tap event that's helpful though. When I print the event.controls.data I just get 'None'. But I can see the text in the cell that I'm clicking / tapping on the app. Any help is greatly appreciated. Code sampledef row_tapped(e):
print("Row tapped.")
print(e.control.data)
def set_peer_tbl():
row_data = []
for items in get_peer_data:
if items["connected"]:
conn = ft.Icon(name=ft.Icons.CHECK, color=ft.colors.GREEN)
else:
conn = ft.Icon(name=ft.Icons.CLOSE, color=ft.colors.RED)
row_data.append(ft.DataRow(
cells=[
ft.DataCell(ft.Text(items["hostname"]), on_tap=row_tapped),
ft.DataCell(conn)
]
))
return row_data
page.add(
ft.Row([
ft.Column([
ft.DataTable(
columns=[
ft.DataColumn(ft.Text("Peer Name")),
ft.DataColumn(ft.Text("Status"))
],
rows=get_row_data,
),
],
scroll=True,
),
ft.VerticalDivider(width=9, thickness=3),
ft.Column([
ft.Text("Details", theme_style=ft.TextThemeStyle.DISPLAY_SMALL)
])
],
expand=1,
)
) Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
e.control
represents theDataCell
. So, to get theText
control you can doe.control.content
, and to get the text/string, you can doe.control.content.value
.