How to center header using aggrid? #2804
-
QuestionI can use ui.aggrid(
{
'columnDefs': [{'field': 'name', 'headerName': 'Name', 'cellStyle': {'textAlign': 'center'}}],
'rowData': [{'name': 'Alice'}, {'name': 'Bob'}],
}
) |
Beta Was this translation helpful? Give feedback.
Answered by
falkoschindler
Apr 3, 2024
Replies: 1 comment 1 reply
-
Hi @tz301, According to https://stackoverflow.com/questions/46490177/how-can-i-center-the-text-in-the-headers-for-an-ag-grid-control we can't control the header alignment via AG Grid options, but with custom CSS: ui.add_style('''
.ag-header-cell-label {
justify-content: center;
}
''')
ui.aggrid({
'columnDefs': [{'field': 'name', 'headerName': 'Name', 'cellStyle': {'textAlign': 'center'}}],
'rowData': [{'name': 'Alice'}, {'name': 'Bob'}],
}) Or if you want to target a specific AG Grid element: ui.add_style('''
.my-aggrid .ag-header-cell-label {
justify-content: center;
}
''')
ui.aggrid({
'columnDefs': [{'field': 'name', 'headerName': 'Name', 'cellStyle': {'textAlign': 'center'}}],
'rowData': [{'name': 'Alice'}, {'name': 'Bob'}],
}).classes('my-aggrid') ![]() |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tz301
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @tz301,
According to https://stackoverflow.com/questions/46490177/how-can-i-center-the-text-in-the-headers-for-an-ag-grid-control we can't control the header alignment via AG Grid options, but with custom CSS:
Or if you want to target a specific AG Grid element: