Duplicate Check
Describe the requested feature
Please add (when possible) a sort arrow positioning attribute:
Example: sort_arrow_alignment="start"
...or:
sort_arrow_alignment="end"
...to DataTable2, so that users can force the position of the sort arrow to the left (start) or right (end) of all column headers.
We currently see that the sort arrow can be on either the right:
...or left-hand side:
...but have no way of forcing one side or the other for all columns (for a more consistent look).
Thank you,
Nelson
Suggest a solution
No response
Screenshots
No response
Additional details
import flet as ft
from flet_datatable2 import DataTable2, DataColumn2
def main(page: ft.Page):
page.title = "Example Table"
page.scroll = "adaptive"
page.padding = 20
data = [
["Alice", "Engineering", 28],
["Bob", "Marketing", 34],
["Charlie", "Finance", 41],
["Diana", "Engineering", 25],
["Ethan", "HR", 38],
]
sort_column_index = None
sort_ascending = True
def build_rows():
return [
ft.DataRow(
cells=[
ft.DataCell(ft.Text(name)),
ft.DataCell(ft.Text(dept)),
ft.DataCell(ft.Text(str(age))),
]
)
for name, dept, age in data
]
def sort_handler(e: ft.DataColumnSortEvent):
nonlocal sort_column_index, sort_ascending, data
sort_column_index = e.column_index
sort_ascending = e.ascending
data.sort(key=lambda row: row[sort_column_index], reverse=not sort_ascending)
table.rows = build_rows()
table.sort_column_index = sort_column_index
table.sort_ascending = sort_ascending
page.update()
table = DataTable2(
columns=[
DataColumn2(ft.Text("Name"), size=200, on_sort=sort_handler),
DataColumn2(ft.Text("Department"), size=200, on_sort=sort_handler),
DataColumn2(ft.Text("Age"), numeric=True, size=100, on_sort=sort_handler),
],
rows=build_rows(),
heading_row_height=40,
data_row_height=40,
column_spacing=10,
fixed_top_rows=1,
fixed_left_columns=1,
sort_column_index=sort_column_index,
sort_ascending=sort_ascending,
)
page.add(ft.Text("Example Table", size=20, weight="bold"), table)
if name == "main":
ft.run(main)
Duplicate Check
Describe the requested feature
Please add (when possible) a sort arrow positioning attribute:
Example: sort_arrow_alignment="start"
...or:
sort_arrow_alignment="end"
...to DataTable2, so that users can force the position of the sort arrow to the left (start) or right (end) of all column headers.
We currently see that the sort arrow can be on either the right:
...or left-hand side:
...but have no way of forcing one side or the other for all columns (for a more consistent look).
Thank you,
Nelson
Suggest a solution
No response
Screenshots
No response
Additional details
import flet as ft
from flet_datatable2 import DataTable2, DataColumn2
def main(page: ft.Page):
page.title = "Example Table"
page.scroll = "adaptive"
page.padding = 20
if name == "main":
ft.run(main)