Each column in a grid has a header that displays the column name and provides access to features like sorting,
filtering, and column menus. These column headers are configurable.
When no header name is provided, the grid will derive the header name from the provided field. If the field value uses
Camel Case it will insert spaces between word breaks to build a readable header name.
columnDefs = [
# header name will be 'Athlete'
{ 'field': 'athlete' },
# header name will be 'First Name'
{ 'field': 'firstName' },
# header name will be 'foo'
{ 'headerName': 'foo', 'field': 'bar' }
]
Use the following properties to adjust the height of headers.
headerHeight
- The height in pixels for the row containing the column label header. If not specified, it uses theheader-height
.groupHeaderHeight
- The height in pixels for the rows containing header column groups. If not specified, itheaderHeight
.floatingFiltersHeight
- The height in pixels for the row containing the floating filters. If not specified, it usesheader-height
.pivotHeaderHeight
(AG Grid Enterprise) - The height in pixels for the row containing the columns when in pivot mode.headerHeight
.pivotGroupHeaderHeight
(AG Grid Enterprise) - The height in pixels for the row containing header column groups whengroupHeaderHeight
.Those properties are set using dashGridOptions
, the example below uses the properties:
dashGridOptions = {
'groupHeaderHeight': 75,
'headerHeight': 150,
'floatingFiltersHeight': 40,
}
Text labels on headers display horizontally by default. If you want to change the text label orientation, you have to
modify the CSS classes used for headers and set the necessary header heights using the properties above.
The following example shows how you can provide a unique look and feel to the headers modifying some CSS
classes .ag-header-*
and setting the header heights using dashGridOptions
:
View the CSS classes used for this example
These CSS classes must be added to any *.css
file in the assets folder.
See Loading CSS files for more information.
.header1 .ag-header-cell-label {
/*Necessary to allow for text to grow vertically*/
height: 100%;
padding: 0 !important;
}
.header1 .ag-header-group-cell {
font-size: 50px;
}
.header1 .ag-header-cell-label .ag-header-cell-text {
/*Force the width corresponding at how much width
we need once the text is laid out vertically*/
width: 55px;
writing-mode: vertical-lr;
-ms-writing-mode: tb-lr;
line-height: 2em;
margin-top: 60px;
}
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 column’s 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.
Add tooltips to headers by setting headerTooltip
on the column definitions. You can also configure the time it takes
for a tooltip to display on hover, using tooltipShowDelay
on dashGridOptions
. The default is 2000
ms.
See Tooltips for details.
Here, we set tooltips for all columns, except “country”, and set the tooltipShowDelay
to 500
ms.
Most applications will use the Provided Header Component. It provides functionality such as Sorting, Filtering and Column Menu.
You can provide an HTML template to the Default Header Component for simple layout changes. This is the default template used in AG Grid:
<div>
<span><span>
<span><span>
<div>
<span><span>
<span><span>
<span><span>
<span><span>
<span><span>
<span><span>
<div>
<div>
When you provide your own template, everything should work as expected as long as you re-use the same refs.
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.
eMenu
: The container where the column menu icon will appear to enable opening the column menu.eFilterButton
: The container where the column filter icon will appear to enable opening the filter (when using columnMenu = 'new'
).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 on 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.Templates are not meant to let you configure the AG Grid header icons such as the filter and sort icons. If you are
looking to change those icons, check our Custom Icons section.
This example shows how to customize the provided template to show additional icons with the header name.
Set the template using headerComponentParams
in the columnDefs
or use defaultColDef
to set for all Columns.
template_with_icon = """
<div>
<span><span>
<span><span>
<div>
<span><span>
<span><span>
<span><span>
<span><span>
<span><span>
<i><i>
<span><span>
<span><span>
<div>
<div>
"""
columnDefs = [
{"field": "gold", "headerComponentParams": {"template": template_with_icon}},
# other columns...
]
Note that in order to render HTML, it’s necessary to set dangerously_allow_code=True
dag.AgGrid(
dangerously_allow_code=True
)
Note that specifying your own templates is compatible with other configurations:
suppressHeaderMenuButton
is specified in: Athlete columnsortable=False
is specified in the “Sport” columnColumn Headers by default use the Provided Header Component. The default can be overridden with Custom Header Component.
Please see the AG Grid documentation for more information. Note that when using Custom Header Components, it’s necessary to include
your own JavaScript functions for sorting, filtering and column menus.