Column Headers can be styled using CSS classes and inline styles. Header row heights can be configured statically or set to adjust automatically based on content.
Header Style Copy Link
Used to provide CSS styles directly (not using a class) to the header. Can be either an object of CSS styles, or a function returning an object of CSS styles.
Properties available on the ColDef<TData = any, TValue = any> interface.
An object of CSS values / or function returning an object of CSS values for a particular header. |
<ag-grid-angular
[columnDefs]="columnDefs"
/* other grid options ... */ />
this.columnDefs = [
// applies to header and floating filter header
{
headerName: 'Static Styles',
field: 'static',
headerStyle: { color: 'red', 'background-color': 'green' }
},
{
headerName: 'Dynamic Styles',
field: 'dynamic',
headerStyle: params => {
// only style floating filter
if (params.floatingFilter) {
return { backgroundColor: 'green' };
}
return null;
}
},
]; Header Class Copy Link
Provides a class for the header. Can be a string (a class), array of strings (array of classes), or a function (that returns a string or an array of strings).
Properties available on the ColDef<TData = any, TValue = any> interface.
CSS class to use for the header cell. Can be a string, array of strings, or function. |
<ag-grid-angular
[columnDefs]="columnDefs"
/* other grid options ... */ />
this.columnDefs = [
{
headerName: 'Static Class',
field: 'static',
headerClass: 'my-class'
},
{
headerName: 'Static Array of Classes',
field: 'staticArray',
headerClass: ['my-class1','my-class2'],
},
{
headerName: 'Function Returns String',
field: 'function',
headerClass: params => {
return params.columnGroup ? 'my-custom-column-group' : 'my-custom-column';
},
}
]; Header Class & Style Example Copy Link
Below shows both headerStyle and headerClass in a full working example. The example demonstrates the following:
- Athlete Details: uses
headerStylestatic object. - Athlete: uses
headerStylestatic object functions. This also causes the floating filter to be styled. - Country: uses
headerStylefunction callback. This allows to set a different background color for the header and floating filter. - Sport: uses
headerClassto add thesport-headerclass to the header. - Medal Details: uses
headerStylecallback function to toggle different styles when the group is expanded or collapsed.
Header Height Copy Link
These properties can be used to change the different heights used in the headers.
The height in pixels for the row containing the column label header. If not specified, it uses the theme value of header-height. |
The height in pixels for the rows containing header column groups. If not specified, it uses headerHeight. |
The height in pixels for the row containing the floating filters. If not specified, it uses the theme value of header-height. |
The height in pixels for the row containing the columns when in pivot mode. If not specified, it uses headerHeight. |
The height in pixels for the row containing header column groups when in pivot mode. If not specified, it uses groupHeaderHeight. |
Hide any column header rows that would only contain padded groups. |
As you can see in the example below, if you change any of the header heights, this change will be reflected automatically. Note how if the value is cleared (set to undefined), it might reuse other values. To see all the interactions check the properties descriptions at the top of the page.
Auto Header Height Copy Link
The column header row can have its height set automatically based on the content of the header cells. This is most useful when used together with Custom Header Components or when using the wrapHeaderText column property.
To enable this, set autoHeaderHeight=true on the column definition you want to adjust the header height for. If more than one column has this property enabled, then the header row will be sized to the maximum of these columns' header cells so no content overflows.
The example below demonstrates using the autoHeaderHeight property in conjunction with the wrapHeaderText property, so that long column names are fully displayed.
- Note that the long column header names wrap onto another line.
- Try making a column smaller by dragging the resize handle on the column header, observe that the header will expand so the full header content is still visible.
Text Orientation Copy Link
By default, the text label for the header is display horizontally, i.e. as normal readable text. To display the text in another orientation you have to provide your own CSS to change the orientation and also provide the adequate header heights using the appropriate grid property.
The following example shows how you can provide a unique look and feel to the headers. Note that:
- The header heights have all been changed via grid options:
<ag-grid-angular
[groupHeaderHeight]="groupHeaderHeight"
[headerHeight]="headerHeight"
[pivotHeaderHeight]="pivotHeaderHeight"
[pivotGroupHeaderHeight]="pivotGroupHeaderHeight"
/* other grid options ... */ />
// Group columns
this.groupHeaderHeight = 75;
// Label columns
this.headerHeight = 150;
// Pivoting, requires turning on pivot mode. Label columns
this.pivotHeaderHeight = 100;
// Pivoting, requires turning on pivot mode. Group columns
this.pivotGroupHeaderHeight = 50;- The grouped column header
Athlete Detailshas a specific style applied to it to make it bigger. Note that the style is slightly different depending if pivoting or not:
.ag-pivot-off .ag-header-group-cell {
font-size: 50px;
color: red;
}
.ag-pivot-on .ag-header-group-cell {
font-size: 25px;
color: green;
}
- The column labels have CSS applied to them so they are displayed vertically.
.ag-header-cell-label {
/* Necessary to allow for text to grow vertically */
height: 100%;
padding: 0 !important;
}
.ag-header-cell-label .ag-header-cell-text {
/* Force the width corresponding to how much width
we need once the text is laid out vertically */
width: 30px;
transform: rotate(90deg);
margin-top: 50px;
/* Since we are rotating a span */
display: inline-block;
}
- The styling of the column labels have also been tweaked depending if pivoting or not.
.ag-pivot-off .ag-header-cell-label {
color: #8a6d3b;
}
.ag-pivot-on .ag-header-cell-label {
color: #1b6d85;
font-weight: bold;
}
Next Up Copy Link
Continue to the next section: Custom Header Components.