I found a piece of code on the internet for kivymd, where I can add or remove text field values to the data table by pressing the Add button (as shown below). But is this possible for Flet Python? How? Even I have appended all the rows of the data table in one list, how can I do this in flet? The information in the link below is not useful for me link I have written the following pieces of code in Flat Python
import flet as ft
from flet import *
class App(UserControl):
first_name = ft.TextField(label="First name",text_align=ft.TextAlign.RIGHT, width=185,height=50)
last_name = ft.TextField(label="Last name",text_align=ft.TextAlign.RIGHT, width=185,height=50)
Age = ft.TextField(label="Age",text_align=ft.TextAlign.RIGHT, width=185,height=50)
data_table = ft.DataTable(
columns=[
ft.DataColumn(ft.Text("First name")),
ft.DataColumn(ft.Text("Last name")),
ft.DataColumn(ft.Text("Age")),
ft.DataColumn(ft.Text("No.")),
],
rows=[
ft.DataRow([ft.DataCell(ft.Text("1")), ft.DataCell(ft.Text(f"{First_name}")), ft.DataCell(ft.Text(f"{Last_name}"))
, ft.DataCell(ft.Text(f"{Age}"))
],),
],
)
def add_btn(e):
pass
def build(self):
return Column(
controls=[
Container(
width=Container.width.fget,
# width=1200,
height=300,
# bgcolor=colors.AMBER_300,
bgcolor="#ffffe0",
border_radius=border_radius.all(5),
content=Column(
controls=[
Row(
# alignment="spaceAround",
spacing=2,
controls=[
# self.txt_number
Container(
margin=margin.only(top=10,right=10),
width=180,
height=50,
bgcolor="#ffffe0",
content=Column(controls=[self.first_name])
),
Container(
margin=margin.only(top=10, right=5),
width=185,
height=50,
bgcolor="#ffffe0",
content=Column(controls=[self.last_name])
),
Container(
margin=margin.only(top=10, right=5),
width=185,
height=50,
bgcolor="#ffffe0",
content=Column(controls=[self.Age])
),
ElevatedButton(
text="Elevated button",
bgcolor="Green",
width=200,
height=40,
on_click= self.add_btn,
),
],
),
),
Container(
width=Container.width.fget,
# width=1200,
height=300,
# bgcolor=colors.AMBER_300,
bgcolor="#ffffe0",
border_radius=border_radius.all(5),
content=Column(
controls=[
self.data_table
],
),
),
]
)
def main(page: Page):
page.title = "flet tutorial"
page.rtl =True
page.window_width =1200
page.window_height=700
page.window_resizable=False
page.bgcolor ="#e249fc"
page.update()
app = App()
page.add(app)
if __name__ =="__main__":
flet.app(target=main)