Expand All

  Getting Started

  Reference

  Features

  Row Models

  Themes

  Components

  Examples

Misc

Github stars make projects look great. Please help, donate a star, it's free.
Read about ag-Grid's Partnership with webpack.
Get informed on releases and other ag-Grid news only - never spam.
Follow on Twitter

Column Headers

Each column has a header at the top that typically displays the column name and has access to column features, such as sorting, filtering and a column menu. This page explains how you can manage the headers.

Header Templates

You can provide a header template used by the default header component for simple layout changes. If you want to change the behaviour, please look at creating your own Custom Header Component. The template for the default header is specified in columnDef.headerParams.template

This is the default template used in ag-grid

<div class="ag-cell-label-container" role="presentation"> <span ref="eMenu" class="ag-header-icon ag-header-cell-menu-button"></span> <div ref="eLabel" class="ag-header-cell-label" role="presentation"> <span ref="eText" class="ag-header-cell-text" role="columnheader"></span> <span ref="eFilter" class="ag-header-icon ag-filter-icon"></span> <span ref="eSortOrder" class="ag-header-icon ag-sort-order" ></span> <span ref="eSortAsc" class="ag-header-icon ag-sort-ascending-icon" ></span> <span ref="eSortDesc" class="ag-header-icon ag-sort-descending-icon" ></span> <span ref="eSortNone" class="ag-header-icon ag-sort-none-icon" ></span> </div> </div>

When you provide your own template, everything should work as expected as long as you reuse the same refs.

Ref Description
eLabel The container where there is going to be an onClick mouse listener to trigger the sort.
eText The text displayed on the column
eFilter The container with the icon that will appear if the user filters this column.
eSortOrder In case of sorting my multiple columns, this shows the index that represents the position of this column in the order.
eSortAsc In case of sorting ascending the data in the column, this shows the associated icon.
eSortDesc In case of sorting descending the data in the column, this shows the descending icon.
eSortNone In case of no sort being applied, this shows the associated icon. Note this icon by default is empty

The ref parameters are used by the grid to identify elements to add functionality to. If you leave an element out of your template, the functionality will not be added. For example if you do not specify eLabel then the column will not react to click events for sorting.

Templates are not meant to let you configure icons, If you are looking to change the icons, check our icon docs

Example - Simple Header Templates

In the following example you can see how we are reusing the default grid template to change the layout of the elements.

defaultColDef : { width: 100, headerComponentParams : { template: '<div class="ag-cell-label-container" role="presentation">' + ' <span ref="eMenu" class="ag-header-icon ag-header-cell-menu-button"></span>' + ' <div ref="eLabel" class="ag-header-cell-label" role="presentation">' + ' <span ref="eSortOrder" class="ag-header-icon ag-sort-order" ></span>' + ' <span ref="eSortAsc" class="ag-header-icon ag-sort-ascending-icon" ></span>' + ' <span ref="eSortDesc" class="ag-header-icon ag-sort-descending-icon" ></span>' + ' <span ref="eSortNone" class="ag-header-icon ag-sort-none-icon" ></span>' + ' ** <span ref="eText" class="ag-header-cell-text" role="columnheader"></span>' + ' <span ref="eFilter" class="ag-header-icon ag-filter-icon"></span>' + ' </div>' + '</div>' } }

Note that specifying your own templates is compatible with other configurations:

  • suppressMenu is especified in: Athlete, Country, Date and Bronze columns
  • suppressSorting is especified in: Age, Year, Sport Silver and Total columns
  • Gold is the only column that doesn't have suppressSorting or suppressSort

Header Height

These properties can be used to change the different heights used in the headers.

headerHeight The height for the row containing the column label header. If not specified the default is 25px.
groupHeaderHeight The height for the rows containing header column groups. If not specified, it uses headerHeight.
floatingFiltersHeight The height for the row containing the floating filters. If not specified the default is 20px.
pivotHeaderHeight The height for the row containing the columns when in pivot mode. If not specified, it uses headerHeight.
pivotGroupHeaderHeight The height for the row containing header column groups when in pivot mode. If not specified, it uses groupHeaderHeight.

All these properties also have setter methods that can be called from the api and will change the header heights dynamically.

setHeaderHeight(heightInPx) Sets the height for the row containing the column label header.
setGroupHeaderHeight(heightInPx) Sets the height for the rows containing header column groups.
setFloatingFiltersHeight(heightInPx) Sets the height for the row containing the floating filters.
setPivotHeaderHeight(heightInPx) Sets the height for the row containing the columns when in pivot mode.
setPivotGroupHeaderHeight(heightInPx) Sets the height for the row containing header column groups when in pivot mode.

Text Orientation

By default, the text label for the header is display horizontally, ie 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.

Header Height and Text Orientation Example

The following example shows how you can provide a unique look & feel to the headers. Note that:

  • The header heights have all been changed in the gridOptions: /* Group columns */ groupHeaderHeight:75, /* Label columns */ headerHeight: 150, /* Floating filter */ floatingFiltersHeight:50, /* Pivoting, requires turning on pivot mode. Label columns */ pivotGroupHeaderHeight:50, /* Pivoting, requires turning on pivot mode. Group columns */ pivotGroupHeaderHeight:100,
  • The grouped column header Athlete Details has an 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-cell-label-container{ /*Necessary to allow for text to grow vertically*/ height: 100%; } .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 at how much width we need once the text is layed out vertically*/ width: 30px; transform: rotate(90deg); margin-top: 50px; /*Since we are rotating a span*/ display: inline-block; }
  • The floating filters are using a much bigger area and the font used is bigger and bolder. .ag-floating-filter-body input { height:49px; } .ag-floating-filter-button { margin-top: -49px; } .ag-floating-filter-button button { height:49px } .ag-floating-filter-body input { font-size: 15px; font-weight: bold; }
  • The styling of the column labels have also be 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; }

Dynamic Header Heights

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 set to null, it might reuse other values. To see all the interactions check the properties descriptions at the top of the page

Refresh Headers and Footers

If you call api.recomputeAggregates(), all header and footer rows will subsequently get ripped out and redrawn to show the new aggregate values. If you want to refresh all headers and footers without recomputing the aggregates, you can call api.refreshCells() - useful if you want to refresh for reasons other than the aggregates being recomputed.

Custom Header

Header templates are meant to be used for simple UI customisation, if you need to have more control over the header check how to create your own Header Components.