I am trying to make a sorted DataTable in Flet but it doesn't seem to work and I don't know why. My code is the following but it doesn't sort the table and it doesn't display the sort indicator either.
import flet as ft
import random
class Empleado:
def __init__(self):
nombres = ["nombre1", "nombre2", "nombre3", "nombre4", "nombre5", "nombre6", "nombre7"]
apellidos = ["apellido1", "apellido2", "apellido3", "apellido4", "apellido5", "apellido6", "apellido7"]
self.numero_legajo = random.randint(1,50)
self.nombre = random.choice(nombres)
self.apellido = random.choice(apellidos)
self.cuil = random.randint(100000000000, 999999999999)
def main(page: ft.Page):
lista_empleados = [Empleado() for i in range(5)]
page.add(
ft.DataTable(
columns=[
ft.DataColumn(ft.Text("Legajo")),
ft.DataColumn(ft.Text("Nombre y Apellido")),
ft.DataColumn(ft.Text("C.U.I.L."))
],
rows=[
(
ft.DataRow(
cells=[
ft.DataCell(ft.Text(value=empleado.numero_legajo)),
ft.DataCell(ft.Text(value=f"{empleado.nombre} {empleado.apellido}")),
ft.DataCell(ft.Text(value=empleado.cuil)),
],
data=empleado
)
) for empleado in lista_empleados
],
sort_column_index=0,
sort_ascending=False,
)
)
ft.app(main)