Skip to main content

DataTable2 is now DataTable with scroll

note

This guide is accurate as of Flet 1.2.0. Later releases might add new APIs or additional migration paths.

The breaking changes and deprecations index lists the guides created for each release.

Summary​

DataTable has a scrolling mode: set scroll, and the table fills its parent and scrolls itself, with a fixed header row, optional fixed left columns, and columns that share the table width by size. Everything DataTable2 from the flet-datatable2 package did now works on DataTable in this mode.

The flet-datatable2 package is deprecated:

  • DataTable2, DataColumn2 and DataRow2 still work. They now send Flet's own DataTable, DataColumn and DataRow, with their renamed properties mapped, and log a deprecation warning.
  • flet_datatable2.DataColumnSize is now ft.DataColumnSize.
  • The package no longer has a Flutter part, so flet build doesn't bundle an extension for it.

Context​

The two tables overlapped so much that you had to know how they differed before you could pick one. They differ in layout, not in features:

DataTableDataTable2
SizeAs big as its contentFills its parent, needs a bounded height
ScrollingScrolls with a parent ColumnScrolls itself, both axes
Column widthsMeasured from the cellsShares of the table width (S/M/L), or fixed
HeaderScrolls awayFixed

So there is now one table, and scroll picks the layout. When it is not set, DataTable works as before.

Two DataTable2 properties get new names, because their old names already mean something else on every control:

  • min_width is now min_content_width: the width the columns keep before the table scrolls horizontally. min_width is the minimum width of the table itself, as on every LayoutControl.
  • bottom_margin is now bottom_padding: the space after the last row is inside the scrolling area, unlike margin, which is outside the table.

Migration guide​

Replace flet-datatable2 classes with the core ones, and remove flet-datatable2 from your project's dependencies:

flet-datatable2Flet 1.2
fdt.DataTable2(...)ft.DataTable(scroll=ft.ScrollMode.AUTO, ...)
fdt.DataColumn2(size=S, fixed_width=w)ft.DataColumn(size=ft.DataColumnSize.S, width=w)
fdt.DataRow2(specific_row_height=h, on_tap=...)ft.DataRow(height=h, on_tap=...)
data_row_height=hdata_row_min_height=h, data_row_max_height=h
min_width=wmin_content_width=w
bottom_margin=mbottom_padding=m
Both visible_*_scroll_bar flags set to Truescroll=ft.ScrollMode.ALWAYS
fdt.DataColumnSizeft.DataColumnSize
Every other propertySame name on ft.DataTable

DataColumn.width includes all cell padding. To preserve a legacy fixed column's rendered width, start with max(50, fixed_width) and include any outside table margin on that column. For example, a last column with fixed_width=80 and the default 24-pixel horizontal margin becomes width=104.

The deprecated wrapper also supports setting scrollbar visibility separately for each axis. On the core table, scroll applies to both axes.

Before:

import flet_datatable2 as fdt

fdt.DataTable2(
expand=True,
min_width=600,
data_row_height=40,
fixed_left_columns=1,
columns=[
fdt.DataColumn2(ft.Text("Name"), size=fdt.DataColumnSize.L),
fdt.DataColumn2(ft.Text("Qty"), numeric=True, fixed_width=80),
],
rows=[...],
)

After:

ft.DataTable(
scroll=ft.ScrollMode.AUTO,
expand=True,
min_content_width=600,
data_row_min_height=40,
data_row_max_height=40,
fixed_left_columns=1,
columns=[
ft.DataColumn(ft.Text("Name"), size=ft.DataColumnSize.L),
ft.DataColumn(ft.Text("Qty"), numeric=True, width=104),
],
rows=[...],
)

DataColumn2 columns were size S by default. A DataColumn without size is size S too.

DataColumn.width also works in the default mode, where it fixes the column's width instead of measuring it from its cells.

Timeline​

  • Deprecated in: 1.2.0
  • Removal in: 1.5.0

References​