DataTable
A Material Design data table.
Example:
ft.DataTable(
columns=[
ft.DataColumn(label=ft.Text("Name")),
ft.DataColumn(label=ft.Text("Role")),
],
rows=[
ft.DataRow(
cells=[
ft.DataCell(ft.Text("Alice")),
ft.DataCell(ft.Text("Engineer")),
]
),
ft.DataRow(
cells=[
ft.DataCell(ft.Text("Bob")),
ft.DataCell(ft.Text("Designer")),
]
),
],
)
A table with 100 or more rows builds only the rows near the visible part
of the page, so it loads and scrolls quickly with thousands of rows. This
needs every row to be the same height, which is the default (when
data_row_min_height equals data_row_max_height), and
either all rows or none to handle on_select_change.
Its columns are as wide as the header, the widest texts of each column,
and the rows shown so far: a column whose widest cell isn't a Text
widens when that cell scrolls into view.
Controls in rows that aren't built have no widget yet, so methods such
as focus(), scrolling to their key, and autofocus don't work on
them until their row scrolls into view. Set
build_rows_on_demand to False to build every row.
In scrolling mode, rows can have different heights
(DataRow.height), but rows are built on demand only while
fixed_top_rows is 1 or more.
The table has two layout modes:
- Default (
scrollnot set): the table is as big as its content and scrolls with its parent, such as a scrollingColumn. Each column is as wide as its widest cell, or itsDataColumn.width. - Scrolling (
scrollset): the table fills its parent and scrolls itself in both directions, with a fixed header row (fixed_top_rows) and optional fixed left columns (fixed_left_columns). Columns share the table width by theirDataColumn.size, or have a fixedDataColumn.width. The table needs a bounded height: setexpand, orheight.

Inherits: LayoutControl
Properties
bgcolor- The background color for this table.border- The border around the table.border_radius- Border corners.bottom_padding- Space after the last row, inside the scrolling area.build_rows_on_demand- Whether a table with 100 or more rows builds only the rows near the visible part of the page.checkbox_alignment- The alignment of the checkboxes in the checkbox column.checkbox_horizontal_margin- Horizontal margin around the checkbox, if it is displayed.clip_behavior- Defines how the contents of this table are clipped.column_spacing- The horizontal margin between the contents of each data column.columns- A list ofDataColumncontrols describing table columns.data_row_checkbox_theme- The theme of the checkboxes in the data rows.data_row_color- The background color for the data rows.data_row_max_height- The maximum height of each row (excluding the row that contains column headings).data_row_min_height- The minimum height of each row (excluding the row that contains column headings).data_text_style- The text style of the datarows.divider_thickness- The width of the divider that appears betweenrows.empty- A control shown under the heading row when the table has norows.fixed_columns_color- The background color of the fixed left columns.fixed_corner_color- The background color of the cells that are in both the fixed top rows and the fixed left columns.fixed_left_columns- The number of columns, counting the checkbox column if shown, that stay on the left while the table scrolls.fixed_top_rows- The number of rows, counting the heading row, that stay at the top while the table scrolls.gradient- The background gradient of this table.heading_checkbox_theme- The theme of the heading row's checkbox.heading_row_color- The background color for the heading row.heading_row_decoration- The decoration painted behind the heading row.heading_row_height- The height of the heading row.heading_text_style- The text style for the heading row.horizontal_lines- Set the color and width of horizontal lines between rows.horizontal_margin- The horizontal margin between the edges of this table and the content in the first and last cells of each row.lm_ratio- How wide aDataColumnSize.Lcolumn is, relative to aDataColumnSize.Mone.min_content_width- The width the columns keep when the table is narrower: below it, the table scrolls horizontally.rows- A list ofDataRowcontrols defining table rows.scroll- Turns on scrolling mode and sets how its scroll bars show.show_bottom_border- Whether a border at the bottom of the table is displayed.show_checkbox_column- Whether the control should display checkboxes for selectable rows.show_heading_checkbox- Whether the heading row shows the checkbox that selects every row.sm_ratio- How wide aDataColumnSize.Scolumn is, relative to aDataColumnSize.Mone.sort_arrow_animation_duration- How long the sort arrow takes to turn when the sort order changes.sort_arrow_icon- The icon of the sort arrow in the heading of the sorted column.sort_arrow_icon_color- The color of the sort arrow.sort_ascending- Whether the column mentioned insort_column_index, if any, is sorted in ascending order.sort_column_index- The current primary sort key's column.vertical_lines- Set the color and width of vertical lines between columns.
Events
on_select_all- Invoked when the user selects or unselects every row, using the checkbox in the heading row.
Examples
DataTable
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.DataTable(
expand=True,
columns=[
ft.DataColumn(label=ft.Text("First name")),
ft.DataColumn(label=ft.Text("Last name")),
ft.DataColumn(label=ft.Text("Age"), numeric=True),
],
rows=[
ft.DataRow(
cells=[
ft.DataCell(ft.Text("John")),
ft.DataCell(ft.Text("Smith")),
ft.DataCell(ft.Text("43")),
],
),
ft.DataRow(
cells=[
ft.DataCell(ft.Text("Jack")),
ft.DataCell(ft.Text("Brown")),
ft.DataCell(ft.Text("19")),
],
),
ft.DataRow(
cells=[
ft.DataCell(ft.Text("Alice")),
ft.DataCell(ft.Text("Wong")),
ft.DataCell(ft.Text("25")),
],
),
],
),
)
)
if __name__ == "__main__":
ft.run(main)

Horizontal margin and column spacing
Use horizontal_margin to control the left and right edge spacing of the first and last columns. Use column_spacing to control spacing between columns.
import flet as ft
def _cell(label: str, color: str = ft.Colors.SURFACE_CONTAINER_HIGHEST) -> ft.DataCell:
return ft.DataCell(
ft.Container(
width=90,
height=32,
alignment=ft.Alignment.CENTER,
bgcolor=color,
border=ft.Border.all(1, ft.Colors.BLACK_26),
content=ft.Text(label, size=12, weight=ft.FontWeight.W_600),
)
)
def main(page: ft.Page):
page.scroll = ft.ScrollMode.AUTO
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
page.theme_mode = ft.ThemeMode.DARK
def update_spacing() -> None:
table.horizontal_margin = horizontal_margin_slider.value
table.column_spacing = column_spacing_slider.value
table.update()
def handle_spacing_change(_: ft.Event[ft.Slider]) -> None:
update_spacing()
def set_preset(horizontal_margin: float, column_spacing: float) -> None:
horizontal_margin_slider.value = horizontal_margin
column_spacing_slider.value = column_spacing
horizontal_margin_slider.update()
column_spacing_slider.update()
update_spacing()
horizontal_margin_slider = ft.Slider(
key="horizontal_margin_slider",
min=0,
max=40,
divisions=40,
value=16,
label="{value}",
on_change=handle_spacing_change,
)
column_spacing_slider = ft.Slider(
key="column_spacing_slider",
min=0,
max=40,
divisions=40,
value=16,
label="{value}",
on_change=handle_spacing_change,
)
table = ft.DataTable(
border=ft.Border.all(1, ft.Colors.ON_SURFACE_VARIANT),
horizontal_margin=horizontal_margin_slider.value,
column_spacing=column_spacing_slider.value,
horizontal_lines=ft.BorderSide(1, ft.Colors.ON_SURFACE_VARIANT),
vertical_lines=ft.BorderSide(1, ft.Colors.ON_SURFACE_VARIANT),
heading_row_height=40,
data_row_min_height=40,
data_row_max_height=40,
columns=[
ft.DataColumn(label="Col A"),
ft.DataColumn(label="Col B"),
ft.DataColumn(label="Col C"),
],
rows=[
ft.DataRow(cells=[_cell("A1"), _cell("B1"), _cell("C1")]),
ft.DataRow(cells=[_cell("A2"), _cell("B2"), _cell("C2")]),
],
)
page.appbar = ft.AppBar(title="DataTable spacing")
page.add(
ft.SafeArea(
content=ft.Column(
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[
ft.Container(
width=520,
padding=12,
border=ft.Border.all(1, ft.Colors.OUTLINE_VARIANT),
border_radius=8,
content=ft.Column(
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
controls=[
ft.Text("horizontal_margin (outer edges)"),
horizontal_margin_slider,
ft.Text("column_spacing (between columns)"),
column_spacing_slider,
ft.Row(
wrap=True,
controls=[
ft.FilledButton(
"Reset",
on_click=lambda _: set_preset(16, 16),
),
ft.OutlinedButton(
"Compact preset",
on_click=lambda _: set_preset(0, 0),
),
ft.OutlinedButton(
"Spacious preset",
on_click=lambda _: set_preset(24, 32),
),
],
),
],
),
),
table,
],
),
)
)
if __name__ == "__main__":
ft.run(main)

Adaptive row heights
Setting data_row_max_height to float('inf') (infinity) will cause the DataTable to let each individual row adapt its height to its respective content, instead of all rows having the same height.
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.DataTable(
width=560,
data_row_min_height=48,
data_row_max_height=float("inf"),
columns=[
ft.DataColumn(label="Description"),
ft.DataColumn(label="Notes"),
],
rows=[
ft.DataRow(
cells=[
ft.DataCell("TWO lines visible without overflow"),
ft.DataCell("Line 1\nLine 2"),
],
),
ft.DataRow(
cells=[
ft.DataCell("FOUR lines visible without overflow"),
ft.DataCell("Line 1\nLine 2\nLine 3\nLine 4"),
],
),
ft.DataRow(
cells=[
ft.DataCell("FIVE lines visible without overflow"),
ft.DataCell("Line 1\nLine 2\nLine 3\nLine 4\nLine 5"),
],
),
],
),
)
)
if __name__ == "__main__":
ft.run(main)

Sortable columns and selectable rows
This example demonstrates row selection (including select-all), sortable string and numeric columns, and stable selection across sorts and refreshes.
import flet as ft
def main(page: ft.Page):
page.scroll = ft.ScrollMode.AUTO
inventory_items = [
{"id": 1, "name": "Alpha", "qty": 4},
{"id": 2, "name": "Bravo", "qty": 9},
{"id": 3, "name": "Charlie", "qty": 2},
{"id": 4, "name": "Delta", "qty": 6},
{"id": 5, "name": "Echo", "qty": 3},
{"id": 6, "name": "Foxtrot", "qty": 8},
{"id": 7, "name": "Golf", "qty": 1},
{"id": 8, "name": "Hotel", "qty": 7},
{"id": 9, "name": "India", "qty": 5},
{"id": 10, "name": "Juliet", "qty": 10},
]
displayed_items = list(inventory_items)
selected_item_ids: set[int] = {1, 3, 5}
sort_key_for_column = {
0: lambda item: str(item["name"]).lower(),
1: lambda item: int(item["qty"]),
}
def build_rows(items: list[dict[str, int | str]]) -> list[ft.DataRow]:
return [
ft.DataRow(
selected=item["id"] in selected_item_ids,
on_select_change=handle_row_selection_change,
data=item["id"],
cells=[
ft.DataCell(ft.Text(item["name"])),
ft.DataCell(ft.Text(str(item["qty"]))),
],
)
for item in items
]
def refresh_table_rows() -> None:
table.rows = build_rows(displayed_items)
table.update()
def handle_row_selection_change(e: ft.Event[ft.DataRow]) -> None:
row = e.control
item_id = row.data
is_selected = e.data
if is_selected:
selected_item_ids.add(item_id)
else:
selected_item_ids.discard(item_id)
row.selected = is_selected
row.update()
def handle_select_all(e: ft.Event[ft.DataTable]) -> None:
if e.data:
selected_item_ids.update(int(item["id"]) for item in displayed_items)
else:
selected_item_ids.clear()
refresh_table_rows()
def handle_column_sort(e: ft.DataColumnSortEvent) -> None:
displayed_items.sort(
key=sort_key_for_column[e.column_index],
reverse=not e.ascending,
)
table.sort_column_index = e.column_index
table.sort_ascending = e.ascending
refresh_table_rows()
table = ft.DataTable(
width=700,
bgcolor=ft.Colors.SURFACE_CONTAINER_LOW,
border=ft.Border.all(1, ft.Colors.OUTLINE_VARIANT),
border_radius=10,
vertical_lines=ft.border.BorderSide(1, ft.Colors.OUTLINE_VARIANT),
horizontal_lines=ft.border.BorderSide(1, ft.Colors.OUTLINE_VARIANT),
sort_column_index=0,
sort_ascending=True,
heading_row_color=ft.Colors.SURFACE_CONTAINER_HIGHEST,
heading_row_height=100,
data_row_color={
ft.ControlState.HOVERED: ft.Colors.with_opacity(0.08, ft.Colors.PRIMARY),
ft.ControlState.SELECTED: ft.Colors.with_opacity(0.14, ft.Colors.PRIMARY),
},
show_checkbox_column=True,
on_select_all=handle_select_all,
divider_thickness=1,
column_spacing=200,
columns=[
ft.DataColumn(
label=ft.Text("Item"),
on_sort=handle_column_sort,
),
ft.DataColumn(
label=ft.Text("Quantity"),
tooltip="Numeric quantity",
numeric=True,
on_sort=handle_column_sort,
),
],
rows=build_rows(displayed_items),
)
page.add(
ft.SafeArea(
content=ft.Row(
scroll=ft.ScrollMode.AUTO,
controls=[table],
),
)
)
if __name__ == "__main__":
ft.run(main)

Handling events
import flet as ft
def main(page: ft.Page):
def handle_row_selection_change(e: ft.Event[ft.DataRow]) -> None:
if e.control.data == 1:
row1.selected = not row1.selected
elif e.control.data == 2:
row2.selected = not row2.selected
elif e.control.data == 3:
row3.selected = not row3.selected
table.update()
def handle_column_sort(e: ft.DataColumnSortEvent) -> None:
if e.control.data in [1, 2]:
print(f"{e.column_index}, {e.ascending}")
table.sort_ascending = e.ascending
table.update()
table = ft.DataTable(
width=700,
bgcolor=ft.Colors.TEAL_ACCENT_200,
border=ft.Border.all(2, ft.Colors.RED_ACCENT_200),
border_radius=10,
vertical_lines=ft.border.BorderSide(3, ft.Colors.BLUE_600),
horizontal_lines=ft.border.BorderSide(1, ft.Colors.GREEN_600),
sort_column_index=0,
sort_ascending=True,
heading_row_color=ft.Colors.BLACK_12,
heading_row_height=100,
data_row_color={ft.ControlState.HOVERED: "0x30FF0000"},
show_checkbox_column=True,
divider_thickness=0,
column_spacing=200,
columns=[
ft.DataColumn(
label=ft.Text("Column 1"),
tooltip="This is the first column",
data=1,
on_sort=handle_column_sort,
),
ft.DataColumn(
label=ft.Text("Column 2"),
tooltip="This is a second column",
numeric=True,
data=2,
on_sort=handle_column_sort,
),
],
rows=[
row1 := ft.DataRow(
cells=[ft.DataCell(ft.Text("A")), ft.DataCell(ft.Text("1"))],
selected=True,
on_select_change=handle_row_selection_change,
data=1,
),
row2 := ft.DataRow(
cells=[ft.DataCell(ft.Text("B")), ft.DataCell(ft.Text("2"))],
selected=False,
on_select_change=handle_row_selection_change,
data=2,
),
row3 := ft.DataRow(
cells=[ft.DataCell(ft.Text("C")), ft.DataCell(ft.Text("3"))],
selected=False,
on_select_change=handle_row_selection_change,
data=3,
),
],
)
page.add(
ft.SafeArea(
content=ft.Row(
scroll=ft.ScrollMode.AUTO,
controls=[table],
),
)
)
if __name__ == "__main__":
ft.run(main)

Scrolling mode
By default, a DataTable is as big as its content and scrolls with its parent, such as a
Column with scroll set.
Set scroll to switch the table to scrolling mode. The table then
fills its parent and scrolls itself in both directions:
- the heading row stays on top, and more rows can too (
fixed_top_rows); - the first columns can stay on the left (
fixed_left_columns); - columns share the table width by their
size(S, M or L), or have a fixedwidth; - rows can have their own
height,decorationand tap events, such ason_tapandon_secondary_tap.
Properties that work only in scrolling mode say so in their description.
A table in scrolling mode needs a bounded height: give it expand or a
height. Inside a scrolling Column, it shows an error instead.
ft.DataTable(
scroll=ft.ScrollMode.AUTO,
expand=True,
fixed_left_columns=1,
columns=[
ft.DataColumn(ft.Text("Name"), size=ft.DataColumnSize.L),
ft.DataColumn(ft.Text("Qty"), numeric=True, width=80),
],
rows=[...],
)
Scrolling mode replaces DataTable2 from the deprecated flet-datatable2 package. See
DataTable2 is now DataTable with scroll.
Scrolling, sorting and selection
With scroll set, the table fills its parent and scrolls itself: the header row stays on top and fixed_left_columns stay on the left.
from dataclasses import dataclass
import flet as ft
@dataclass
class Dessert:
name: str
calories: float
fat: float
carbs: float
protein: float
sodium: float
calcium: float
iron: float
desserts = [
Dessert("Frozen Yogurt", 159, 6.0, 24, 4.0, 87, 14, 1),
Dessert("Ice Cream Sandwich", 237, 9.0, 37, 4.3, 129, 8, 1),
Dessert("Eclair", 262, 16.0, 24, 6.0, 337, 6, 7),
Dessert("Cupcake", 305, 3.7, 67, 4.3, 413, 3, 8),
Dessert("Gingerbread", 356, 16.0, 49, 3.9, 327, 7, 16),
Dessert("Jelly Bean", 375, 0.0, 94, 0.0, 50, 0, 0),
Dessert("Lollipop", 392, 0.2, 98, 0.0, 38, 0, 2),
Dessert("Honeycomb", 408, 3.2, 87, 6.5, 562, 0, 45),
Dessert("Donut", 452, 25.0, 51, 4.9, 326, 2, 22),
Dessert("Apple Pie", 518, 26.0, 65, 7.0, 54, 12, 6),
Dessert("Frozen Yougurt with sugar", 168, 6.0, 26, 4.0, 87, 14, 1),
Dessert("Ice Cream Sandwich with sugar", 246, 9.0, 39, 4.3, 129, 8, 1),
Dessert("Eclair with sugar", 271, 16.0, 26, 6.0, 337, 6, 7),
Dessert("Cupcake with sugar", 314, 3.7, 69, 4.3, 413, 3, 8),
Dessert("Gingerbread with sugar", 345, 16.0, 51, 3.9, 327, 7, 16),
Dessert("Jelly Bean with sugar", 364, 0.0, 96, 0.0, 50, 0, 0),
Dessert("Lollipop with sugar", 401, 0.2, 100, 0.0, 38, 0, 2),
Dessert("Honeycomb with sugar", 417, 3.2, 89, 6.5, 562, 0, 45),
Dessert("Donut with sugar", 461, 25.0, 53, 4.9, 326, 2, 22),
Dessert("Apple pie with sugar", 527, 26.0, 67, 7.0, 54, 12, 6),
Dessert("Frozen yougurt with honey", 223, 6.0, 36, 4.0, 87, 14, 1),
Dessert("Ice Cream Sandwich with honey", 301, 9.0, 49, 4.3, 129, 8, 1),
Dessert("Eclair with honey", 326, 16.0, 36, 6.0, 337, 6, 7),
Dessert("Cupcake with honey", 369, 3.7, 79, 4.3, 413, 3, 8),
Dessert("Gingerbread with honey", 420, 16.0, 61, 3.9, 327, 7, 16),
Dessert("Jelly Bean with honey", 439, 0.0, 106, 0.0, 50, 0, 0),
Dessert("Lollipop with honey", 456, 0.2, 110, 0.0, 38, 0, 2),
Dessert("Honeycomb with honey", 472, 3.2, 99, 6.5, 562, 0, 45),
Dessert("Donut with honey", 516, 25.0, 63, 4.9, 326, 2, 22),
Dessert("Apple pie with honey", 582, 26.0, 77, 7.0, 54, 12, 6),
]
def main(page: ft.Page):
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
sorted_desserts = list(desserts)
def handle_row_selection_change(e: ft.Event[ft.DataRow]) -> None:
e.control.selected = not e.control.selected
e.control.update()
def sort_column(e: ft.DataColumnSortEvent) -> None:
sorters = [
lambda d: d.name.lower(),
lambda d: d.calories,
lambda d: d.fat,
lambda d: d.carbs,
lambda d: d.protein,
lambda d: d.sodium,
lambda d: d.calcium,
lambda d: d.iron,
]
sorted_desserts.sort(key=sorters[e.column_index], reverse=not e.ascending)
table.rows = get_data_rows(sorted_desserts)
table.sort_column_index = e.column_index
table.sort_ascending = e.ascending
table.update()
def get_data_columns() -> list[ft.DataColumn]:
return [
ft.DataColumn(
label=ft.Text("Name"),
size=ft.DataColumnSize.L,
on_sort=sort_column,
heading_row_alignment=ft.MainAxisAlignment.START,
),
ft.DataColumn(
label=ft.Text("Calories"),
on_sort=sort_column,
numeric=True,
heading_row_alignment=ft.MainAxisAlignment.END,
),
ft.DataColumn(label=ft.Text("Fat"), on_sort=sort_column, numeric=True),
ft.DataColumn(label=ft.Text("Carbs"), on_sort=sort_column, numeric=True),
ft.DataColumn(
label=ft.Text("Protein"),
on_sort=sort_column,
numeric=True,
),
ft.DataColumn(label=ft.Text("Sodium"), on_sort=sort_column, numeric=True),
ft.DataColumn(
label=ft.Text("Calcium"),
on_sort=sort_column,
numeric=True,
),
ft.DataColumn(label=ft.Text("Iron"), on_sort=sort_column, numeric=True),
]
def get_data_rows(items: list) -> list[ft.DataRow]:
return [
ft.DataRow(
height=50,
on_select_change=handle_row_selection_change,
cells=[
ft.DataCell(content=ft.Text(dessert.name)),
ft.DataCell(content=ft.Text(dessert.calories)),
ft.DataCell(content=ft.Text(dessert.fat)),
ft.DataCell(content=ft.Text(dessert.carbs)),
ft.DataCell(content=ft.Text(dessert.protein)),
ft.DataCell(content=ft.Text(dessert.sodium)),
ft.DataCell(content=ft.Text(dessert.calcium)),
ft.DataCell(content=ft.Text(dessert.iron)),
],
)
for dessert in items
]
table = ft.DataTable(
scroll=ft.ScrollMode.AUTO,
expand=True,
# Keep the checkbox and Name columns in view while scrolling sideways.
fixed_left_columns=2,
show_checkbox_column=True,
column_spacing=0,
heading_row_color=ft.Colors.SECONDARY_CONTAINER,
horizontal_margin=12,
sort_ascending=True,
bottom_padding=10,
min_content_width=900,
on_select_all=lambda: print("All selected"),
columns=get_data_columns(),
rows=get_data_rows(sorted_desserts),
)
page.add(ft.SafeArea(expand=True, content=table))
if __name__ == "__main__":
ft.run(main)

Column widths
In scrolling mode, a column has a fixed width, or a size share of the table width.
import flet as ft
def main(page: ft.Page):
def cell_text(value: str) -> ft.Text:
"""A helper to truncate any overflowing cell text with an ellipsis."""
return ft.Text(value, overflow=ft.TextOverflow.ELLIPSIS, max_lines=1)
page.add(
ft.SafeArea(
expand=True,
content=ft.DataTable(
scroll=ft.ScrollMode.AUTO,
expand=True,
min_content_width=600,
columns=[
# Fixed width: best for predictable, short fields.
ft.DataColumn(label="Name", width=164),
# Relative size S: a small share of the remaining width.
ft.DataColumn(label="Role", size=ft.DataColumnSize.S),
# Relative size L: the largest share of what is left.
ft.DataColumn(label="Recent work", size=ft.DataColumnSize.L),
],
rows=[
ft.DataRow(
cells=[
ft.DataCell(cell_text("Alice Nakamura")),
ft.DataCell(cell_text("Engineer")),
ft.DataCell(
cell_text(
"Led the migration of our checkout service "
"to a set of composable workers, cutting "
"p99 latency in half."
)
),
]
),
ft.DataRow(
cells=[
# Longer than 164px: shows an ellipsis in a fixed column.
ft.DataCell(cell_text("Bartholomew Laurent-Fitzgerald")),
ft.DataCell(cell_text("Designer")),
ft.DataCell(
cell_text(
"Rebuilt the onboarding flow and maintains "
"the internal design-system token registry."
)
),
]
),
ft.DataRow(
cells=[
ft.DataCell(cell_text("Chen")),
ft.DataCell(cell_text("PM")),
ft.DataCell(
cell_text("Owns the Platform Reliability roadmap.")
),
]
),
],
),
)
)
if __name__ == "__main__":
ft.run(main)

Empty state
empty shows a placeholder under the header when the table has no rows.
import flet as ft
def main(page: ft.Page):
page.add(
ft.SafeArea(
expand=True,
content=ft.DataTable(
scroll=ft.ScrollMode.AUTO,
expand=True,
empty=ft.Text("This table is empty."),
columns=[
ft.DataColumn(label=ft.Text("First name")),
ft.DataColumn(label=ft.Text("Last name")),
ft.DataColumn(label=ft.Text("Age"), numeric=True),
],
),
)
)
if __name__ == "__main__":
ft.run(main)

Properties
bgcolorclass-attributeinstance-attribute
bgcolor: ColorValue | None = NoneThe background color for this table.
border_radiusclass-attributeinstance-attribute
border_radius: BorderRadiusValue | None = NoneBorder corners.
bottom_paddingclass-attributeinstance-attribute
bottom_padding: Number | None = NoneSpace after the last row, inside the scrolling area.
Used only in scrolling mode, when DataTable.scroll is set.
build_rows_on_demandclass-attributeinstance-attribute
build_rows_on_demand: bool = TrueWhether a table with 100 or more rows builds only the rows near the visible part of the page.
Set to False to build every row up front, so that every control in the
table has a widget, at the cost of a slower load for long tables.
checkbox_alignmentclass-attributeinstance-attribute
checkbox_alignment: Alignment | None = NoneThe alignment of the checkboxes in the checkbox column.
Defaults to Alignment.CENTER.
Used only in scrolling mode, when DataTable.scroll is set.
checkbox_horizontal_marginclass-attributeinstance-attribute
checkbox_horizontal_margin: Number | None = NoneHorizontal margin around the checkbox, if it is displayed.
clip_behaviorclass-attributeinstance-attribute
clip_behavior: ClipBehavior = ClipBehavior.NONEDefines how the contents of this table are clipped.
column_spacingclass-attributeinstance-attribute
column_spacing: Number | None = NoneThe horizontal margin between the contents of each data column.
columnsinstance-attribute
columns: list[DataColumn]A list of DataColumn controls describing table columns.
Raises:
- ValueError - If there are no visible
columns.
data_row_checkbox_themeclass-attributeinstance-attribute
data_row_checkbox_theme: CheckboxTheme | None = NoneThe theme of the checkboxes in the data rows.
Used only in scrolling mode, when DataTable.scroll is set.
data_row_colorclass-attributeinstance-attribute
data_row_color: ControlStateValue[ColorValue] | None = NoneThe background color for the data rows.
The effective background color can be made to depend on the
ControlState state, i.e. if the row is selected, pressed, hovered,
focused, disabled or enabled. The color is painted as an overlay to the row.
To make sure that the row's InkWell is visible (when pressed, hovered and focused),
it is recommended to use a translucent background color.
data_row_max_heightclass-attributeinstance-attribute
data_row_max_height: Number | None = NoneThe maximum height of each row (excluding the row that contains column headings).
Set to float("inf") for the height of each row to adjust automatically with its
content.
Defaults to 48.0.
Raises:
- ValueError - If it is not greater than or equal to
data_row_min_height.
data_row_min_heightclass-attributeinstance-attribute
data_row_min_height: Number | None = NoneThe minimum height of each row (excluding the row that contains column headings).
Defaults to 48.0.
Raises:
- ValueError - If it is not less than or equal to
data_row_max_height.
data_text_styleclass-attributeinstance-attribute
data_text_style: TextStyle | None = NoneThe text style of the data rows.
divider_thicknessclass-attributeinstance-attribute
divider_thickness: Number = 1.0The width of the divider that appears between rows.
Raises:
- ValueError - If it is not greater than or equal to
0.
emptyclass-attributeinstance-attribute
empty: Control | None = NoneA control shown under the heading row when the table has no rows.
fixed_columns_colorclass-attributeinstance-attribute
fixed_columns_color: ColorValue | None = NoneThe background color of the fixed left columns.
Used only in scrolling mode, when DataTable.scroll is set.
fixed_corner_colorclass-attributeinstance-attribute
fixed_corner_color: ColorValue | None = NoneThe background color of the cells that are in both the fixed top rows and the fixed left columns.
Used only in scrolling mode, when DataTable.scroll is set.
fixed_left_columnsclass-attributeinstance-attribute
fixed_left_columns: int = 0The number of columns, counting the checkbox column if shown, that stay on the left while the table scrolls.
Raises:
- ValueError - If it is negative.
Used only in scrolling mode, when DataTable.scroll is set.
fixed_top_rowsclass-attributeinstance-attribute
fixed_top_rows: int = 1The number of rows, counting the heading row, that stay at the top while the table scrolls.
Raises:
- ValueError - If it is negative.
Used only in scrolling mode, when DataTable.scroll is set.
gradientclass-attributeinstance-attribute
gradient: Gradient | None = NoneThe background gradient of this table.
heading_checkbox_themeclass-attributeinstance-attribute
heading_checkbox_theme: CheckboxTheme | None = NoneThe theme of the heading row's checkbox.
Used only in scrolling mode, when DataTable.scroll is set.
heading_row_colorclass-attributeinstance-attribute
heading_row_color: ControlStateValue[ColorValue] | None = (
None
)The background color for the heading row.
The effective background color can be made to depend on the
ControlState state, i.e. if the row is pressed, hovered,
focused when sorted. The color is painted as an overlay to the row. To make sure
that the row's InkWell is visible (when pressed, hovered and focused), it is
recommended to use a translucent color.
heading_row_decorationclass-attributeinstance-attribute
heading_row_decoration: BoxDecoration | None = NoneThe decoration painted behind the heading row.
Used only in scrolling mode, when DataTable.scroll is set.
heading_row_heightclass-attributeinstance-attribute
heading_row_height: Number | None = NoneThe height of the heading row.
heading_text_styleclass-attributeinstance-attribute
heading_text_style: TextStyle | None = NoneThe text style for the heading row.
horizontal_linesclass-attributeinstance-attribute
horizontal_lines: BorderSide | None = NoneSet the color and width of horizontal lines between rows.
horizontal_marginclass-attributeinstance-attribute
horizontal_margin: Number | None = NoneThe horizontal margin between the edges of this table and the content in the first and last cells of each row.
When a checkbox is displayed, it is also the margin between the checkbox the content in the first data column.
lm_ratioclass-attributeinstance-attribute
lm_ratio: Number = 1.2How wide a DataColumnSize.L column is, relative to a
DataColumnSize.M one.
Raises:
- ValueError - If it is not greater than
0.
Used only in scrolling mode, when DataTable.scroll is set.
min_content_widthclass-attributeinstance-attribute
min_content_width: Number | None = NoneThe width the columns keep when the table is narrower: below it, the table scrolls horizontally.
Unlike min_width, which sets the minimum width of the table itself,
this sets the width of its content.
Used only in scrolling mode, when DataTable.scroll is set.
rowsclass-attributeinstance-attribute
rows: list[DataRow] = field(default_factory=list)A list of DataRow controls defining table rows.
scrollclass-attributeinstance-attribute
scroll: ScrollMode | None = NoneTurns on scrolling mode and sets how its scroll bars show.
If set, the table fills its parent and scrolls itself, with a fixed header
row. It then needs a bounded height: inside a scrolling
Column, set expand or height.
If not set (the default), the table is as big as its content and scrolls with its parent.
show_bottom_borderclass-attributeinstance-attribute
show_bottom_border: bool = FalseWhether a border at the bottom of the table is displayed.
By default, a border is not shown at the bottom to allow for a border around the table defined by decoration.
show_checkbox_columnclass-attributeinstance-attribute
show_checkbox_column: bool = FalseWhether the control should display checkboxes for selectable rows.
If True, a checkbox will be placed at the beginning of each row that is
selectable. However, if DataRow.on_select_change
is not set for any row, checkboxes will not be placed, even if this value is True.
If False, all rows will not display a checkbox.
show_heading_checkboxclass-attributeinstance-attribute
show_heading_checkbox: bool = TrueWhether the heading row shows the checkbox that selects every row.
Used only in scrolling mode, when DataTable.scroll is set.
sm_ratioclass-attributeinstance-attribute
sm_ratio: Number = 0.67How wide a DataColumnSize.S column is, relative to a
DataColumnSize.M one.
Raises:
- ValueError - If it is not greater than
0.
Used only in scrolling mode, when DataTable.scroll is set.
sort_arrow_animation_durationclass-attributeinstance-attribute
sort_arrow_animation_duration: DurationValue | None = NoneHow long the sort arrow takes to turn when the sort order changes.
Defaults to 150 milliseconds.
Used only in scrolling mode, when DataTable.scroll is set.
sort_arrow_iconclass-attributeinstance-attribute
sort_arrow_icon: IconData | None = NoneThe icon of the sort arrow in the heading of the sorted column.
Defaults to Icons.ARROW_UPWARD.
Used only in scrolling mode, when DataTable.scroll is set.
sort_arrow_icon_colorclass-attributeinstance-attribute
sort_arrow_icon_color: ColorValue | None = NoneThe color of the sort arrow.
Used only in scrolling mode, when DataTable.scroll is set.
sort_ascendingclass-attributeinstance-attribute
sort_ascending: bool = FalseWhether the column mentioned in sort_column_index, if any, is sorted in ascending order.
If True, the order is ascending (meaning the rows with the smallest values for
the current sort column are first in the table).
If False, the order is descending (meaning the rows with the smallest values for
the current sort column are last in the table).
sort_column_indexclass-attributeinstance-attribute
sort_column_index: int | None = NoneThe current primary sort key's column.
If specified, indicates that the indicated column is the column by which the data
is sorted. The number must correspond to the index of the relevant column in
columns.
Setting this will cause the relevant column to have a sort indicator displayed.
When this is None, it implies that the table's sort order does not correspond to
any of the columns.
Raises:
- ValueError - If it is out of range relative to the visible
columns.
vertical_linesclass-attributeinstance-attribute
vertical_lines: BorderSide | None = NoneSet the color and width of vertical lines between columns.
Events
on_select_allclass-attributeinstance-attribute
on_select_all: ControlEventHandler[DataTable] | None = NoneInvoked when the user selects or unselects every row, using the checkbox in the heading row.
If this is None, then the DataRow.on_select_change
callback of every rows of this table is invoked appropriately instead.
To control whether a particular row is selectable or not, see
DataRow.on_select_change. This callback is only relevant if
any row is selectable.