I made custom DataCell field, so I can track what exactly is changed inside the DataTable.
And with TextField it’s working, but when I click dropdown it just closes, as it lost focus.
Any idea on how to make dropdown work?
class AllOrdersTableCell(ft.DataCell):
def __init__(self, row_name, column_name, order_number):
super().__init__(content=ft.Row())
self.row_name = row_name
self.column_name = column_name
self.order_number = order_number
self.on_double_tap = self.start_edit
self.text = ft.Text(row_name)
self.text_field = ft.Container(
bgcolor=ft.colors.WHITE,
width=150,
content=ft.TextField(value=row_name,
on_submit=self.save_change,
on_blur=self.cancel_edit),
visible=False,
)
self.status_dropdown = ft.Container(
bgcolor=ft.colors.WHITE,
width=150,
height=150,
content=ft.Dropdown(
border=ft.InputBorder.OUTLINE,
value=row_name,
on_change=self.save_change,
on_blur=self.cancel_edit,
options=[
ft.dropdown.Option('Option 1'),
ft.dropdown.Option('Option 2'),
ft.dropdown.Option('Option 3'),
ft.dropdown.Option('Option 4'),
],
),
visible=False,
)
def build(self):
if self.column_name == 'status':
self.content.controls.append(self.text)
self.content.controls.append(self.status_dropdown)
else:
self.content.controls.append(self.text)
self.content.controls.append(self.text_field)
def start_edit(self, e):
print(f'{self.order_number} - {self.column_name}')
self.content.controls[0].visible = False
self.content.controls[1].visible = True
self.content.controls[1].content.focus()
self.content.update()
def save_change(self, e):
self.content.controls[0].visible = True
self.content.controls[1].visible = False
self.row_name = self.content.controls[1].content.value
self.content.controls[0].value = self.row_name
self.content.update()
def cancel_edit(self, e):
self.content.controls[0].visible = True
self.content.controls[1].visible = False
self.content.controls[1].content.value = self.row_name
self.content.controls[0].value = self.row_name
self.content.update()
I’m expection DropDown to show options, not just become invisible, when i click it
New contributor
arrogantworm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.