[Python] Flet DataTable: row disappears when updating cell content value

Discussão em 'Python' iniciado por Stack, Agosto 28, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using Flet in Python. I have a DataTable where each DataRow stores an object (lote) in row.data. Each row has action buttons in the first cell and then several ft.Text cells with values.

    The issue: when I try to update a cell's value, instead of updating, the row disappears from the table.

    The code:

    def update_lote(lote, values):
    """
    Find a row by its data and update its cells.
    """
    for row in data_table.rows:
    if row.data == lote:
    for i, val in enumerate(values, start=1):

    if isinstance(row.cells.content, ft.Text):
    row.cells.content.value = val # type: ignore
    data_table.update()


    # Sample DataTable
    lote = "lote1"
    corral = {"corral": "101", "seller": "John"}

    data_table = ft.DataTable(
    columns=[
    ft.DataColumn(ft.Text("CORRAL")),
    ft.DataColumn(ft.Text("SELLER")),
    ],
    rows=[
    ft.DataRow(
    data=lote,
    cells=[
    ft.DataCell(ft.Text(corral["corral"])),
    ft.DataCell(ft.Text(corral["seller"])),
    ],
    )
    ],
    )

    # Later: trying to update "CORRAL"
    update_lote(lote, ["202", "John"])


    Expected result: The value in the "CORRAL" column should change when it gets updated.

    Actual result: The row disappears from the DataTable instead of updating.

    Continue reading...

Compartilhe esta Página