[Question] Center data in a DataTable #2488
-
QuestionGood afternoon. Is there a way to center the content of the cells for the datatable? When DataCells are added to DataRows, the content is aligned to the left and it would be better to be able to center it. Thank you Code sampleNo response Error messageNo response ------------------------------------------------------
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
As far as I can tell, the flutter DataTable does not come with alignment. Hence, it is not possible to align the text in a Flet DataTable as well. |
Beta Was this translation helpful? Give feedback.
-
@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): ft.app(target=main)` |
Beta Was this translation helpful? Give feedback.
@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(
…