DataTable2 is now DataTable with scroll
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,DataColumn2andDataRow2still work. They now send Flet's ownDataTable,DataColumnandDataRow, with their renamed properties mapped, and log a deprecation warning.flet_datatable2.DataColumnSizeis nowft.DataColumnSize.- The package no longer has a Flutter part, so
flet builddoesn'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:
DataTable | DataTable2 | |
|---|---|---|
| Size | As big as its content | Fills its parent, needs a bounded height |
| Scrolling | Scrolls with a parent Column | Scrolls itself, both axes |
| Column widths | Measured from the cells | Shares of the table width (S/M/L), or fixed |
| Header | Scrolls away | Fixed |
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_widthis nowmin_content_width: the width the columns keep before the table scrolls horizontally.min_widthis the minimum width of the table itself, as on everyLayoutControl.bottom_marginis nowbottom_padding: the space after the last row is inside the scrolling area, unlikemargin, 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-datatable2 | Flet 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=h | data_row_min_height=h, data_row_max_height=h |
min_width=w | min_content_width=w |
bottom_margin=m | bottom_padding=m |
Both visible_*_scroll_bar flags set to True | scroll=ft.ScrollMode.ALWAYS |
fdt.DataColumnSize | ft.DataColumnSize |
| Every other property | Same 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
- Issue: #7079
- Pull request: #7155
- Docs:
DataTable, Scrolling mode,DataColumnSize - Release notes: Flet 1.2.0