Skip to content

[Question] Center data in a DataTable #2488

Answered by burhansvural
ingdesarr1 asked this question in Q&A
Discussion options

You must be logged in to vote

@ingdesarr1 You can wrap the control you want to add to the DataCell with a Container and use its alignment property.

`import flet as ft

def main(page: ft.Page):
page.add(
ft.DataTable(
columns=[
ft.DataColumn(ft.Text("First name")),
ft.DataColumn(ft.Text("Last name")),
ft.DataColumn(ft.Text("Age"), numeric=True),
],
rows=[
ft.DataRow(
cells=[
ft.DataCell(
content=ft.Container(
alignment=ft.alignment.center,
content=ft.Text("John")
)
),
ft.DataCell(
content=ft.Container(
alignment=ft.alignment.center,
content=ft.Text("Smith")
)),
ft.DataCell(ft.Text("43")),
],
),
ft.DataRow(
cells=[
ft.DataCell(
content=ft.Container(
alignment=ft.alignment.center,
content=ft.Text("Jack")
),
),
ft.DataCell(

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by ndonkoHenri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
help wanted Extra attention is needed
3 participants