Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 3ddb997

Browse files
committed
fixed Alignment error and python version
1 parent 293cc78 commit 3ddb997

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

examples/flet_datatable2_example/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "flet-datatable2-example"
33
version = "1.0.0"
44
description = ""
55
readme = "README.md"
6-
requires-python = ">=3.9"
6+
requires-python = ">=3.10"
77
authors = [
88
{ name = "Flet developer", email = "you@example.com" }
99
]

examples/flet_datatable2_example/src/main.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
import logging
2+
import os
23

34
import flet as ft
45
from data import desserts
56

67
from flet_datatable2 import DataColumn2, DataRow2, DataTable2, Size
78

89
logging.basicConfig(level=logging.DEBUG)
10+
os.environ["FLET_PLATFORM"] = "macos"
911

1012

1113
def main(page: ft.Page):
1214
page.vertical_alignment = ft.MainAxisAlignment.CENTER
1315
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
1416

1517
def select_row(e):
18+
print("on_select_row")
1619
e.control.selected = not e.control.selected
1720
e.control.update()
1821

19-
def sort_column(e):
20-
dt.sort_column_index = e.column_index
21-
dt.sort_ascending = e.ascending
22-
sorted_desserts = sorted(
23-
desserts,
24-
key=lambda d: getattr(d, e.control.label.value.lower()),
25-
reverse=not dt.sort_ascending,
26-
)
27-
dt.rows = get_data_rows(sorted_desserts)
28-
dt.update()
22+
# def sort_column(e):
23+
# print("on_sort")
24+
# #dt.sort_column_index = e.column_index
25+
# # dt.sort_ascending = e.ascending
26+
# # sorted_desserts = sorted(
27+
# # desserts,
28+
# # key=lambda d: getattr(d, e.control.label.value.lower()),
29+
# # reverse=not dt.sort_ascending,
30+
# # )
31+
# # dt.rows = get_data_rows(sorted_desserts)
32+
# # dt.update()
33+
def sort_column(e: ft.DataColumnSortEvent):
34+
print(f"Sorting column {e.column_index}, ascending={e.ascending}")
35+
36+
def all_selected(e):
37+
print("All selected")
2938

3039
def get_data_columns():
3140
data_columns = [
@@ -105,10 +114,11 @@ def get_data_rows(desserts):
105114
sort_ascending=True,
106115
bottom_margin=10,
107116
min_width=600,
117+
on_select_all=all_selected,
108118
columns=get_data_columns(),
109119
rows=get_data_rows(desserts),
110120
),
111121
)
112122

113-
114-
ft.app(main)
123+
ft.run(main, view=ft.AppView.FLET_APP, port=8550)
124+
# ft.app(main)

src/flet_datatable2/datatable2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class DataTable2(ft.ConstrainedControl):
9494
vertical_lines: Optional[ft.BorderSide] = None
9595
checkbox_horizontal_margin: ft.OptionalNumber = None
9696
checkbox_alignment: ft.Alignment = field(
97-
default_factory=lambda: ft.alignment.center
97+
default_factory=lambda: ft.Alignment.center()
9898
)
9999
column_spacing: ft.OptionalNumber = None
100100
data_row_color: ft.ControlStateValue[ft.ColorValue] = None

src/flutter/flet_datatable2/lib/src/datatable2.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ class _DataTable2ControlState extends State<DataTable2Control> {
149149
"sort", {"i": columnIndex, "a": ascending});
150150
}
151151
: null,
152+
//},
153+
// onSort: (columnIndex, ascending) {
154+
// column.triggerEvent("sort", {"i": columnIndex, "a": ascending});
155+
// },
152156
label: column.buildWidget("label")!);
153157
}).toList(),
154158
rows: widget.control.children("rows").map((row) {

0 commit comments

Comments
 (0)