How can I center the text in the headers for an AG-grid control? I have tried using cellstyle and cellclass in the column definition but that did not work. Thank you
You may use this property:
cellStyle: {textAlign: 'center'}
I'm using Angular 8 and AG-Grid is nested deep in some other component.
I had to do this in order to make it work.
.ag-header-group-cell-label {
justify-content: center !important;
}
And, this strictly needs to be under styles.scss
file and not in the component scss file. Or else, it will not work.
Hope this helps someone.
If you want to align your text right, left or center in ag-grid. Then use this:-
cellStyle: { textAlign: 'right' }
cellStyle: { textAlign: 'left' }
cellStyle: { textAlign: 'center' }
It should be:
.ag-header-cell-label {
text-align: center;
}
I'm using react and I just added the following snippet to my Table component's .css
.ag-header-cell-label {
justify-content: center;
}
I'm overriding the .css
class class from ag-grid
which I found via devtools inspection, and discovered it's using flexbox for display.
See example (not react but same concept): https://embed.plnkr.co/O3NI4WgHxkFiJCyacn0r/
To use a custom class, add headerClass: "text-center"
to the column definition and css as follows:
text-center * {
justifyContent: center
}