Configuring Column Header
Summary
- AdapTable users are able to change the Header / Caption of a Column in AG Grid in 2 ways:
- Changes configured in a particular Layout
- Changes set through the
columnHeaderfunction in Column Options
By default, AdapTable will show as the header (or caption) of the Column (ie. the text that appears in the Header Bar) the default value provided in AG Grid's ColumnDefs.
However this can be changed in AdapTable in 2 ways:
- on a per-Layout basis using the
ColumnHeadersproperty - via the
columnHeaderfunction in Column Options
When both are used, the function is always called. The Layout caption is passed into the function so you can honour a user override, keep the AG Grid header, or apply your own value.
Hint
- This page is the source for the text that appears in the Grid header
- To change how the Column is labelled in the AdapTable UI (Settings Panel, Expression Editor, and so on), use
columnFriendlyName— see Adaptable Column
Per Layout
A given Layout can store a caption for a Column using the ColumnHeaders property.
Note
- This enables the same Column to have different Headers / Captions in 2 Layouts
- It also allows the Column's Header to be set at run-time via the AdapTable UI
A custom Column Header can be set in a Layout (using the ColumnHeaders property) in many ways:
- In Layout Initial State (i.e. by developers at design-time)
- Using the
Change Captionmenu option in each Column Menu - In the
Columnssection of the Layout Wizard (via the dropdown which opens an expanded section) - Programmatically using the
setColumnCaptionfunction in Layout API
Hint
- AG Grid makes it easy to wrap Column Headers - useful when the header text is wider than the cell text
- The
wrapHeaderText&autoHeaderHeightprops in Column Defs, when set to true, creates the necessary effect
- This demo shows how to change the Column Header on a per-Layout basis
- In the Initial State for the
StandardLayout we change 'Name' toJavaScript Frameworkand 'Gihub Stars' toFans - Note: we set
wrapHeaderTextandautoHeaderHeightto true in Column Def's to create a better visual effect - We provide a Dashboard button to allow the Header for "Updated" to be set via the Layout API
- Switch between Layouts and note that the
GroupedLayout contains the original Column Headers - Change a Column Header using the
Change HeaderMenu Item in the Column Menu - Change another Column's Header by using the Layout Editor's Wizard
Using a Function
The columnHeader function in Column Options provides a more configurable way to change Column Headers.
The function is always invoked (if provided)
Note
This includes when the current Layout already has a caption for that Column
That lets you choose, per column, between 3 values:
(1) colDefHeaderName: the original AG Grid Column Definition header
(2) a value you compute in the function
(3) layoutSpecificHeaderName: a caption the user (or Initial State) set on the Layout
The typical pattern is: use (2) unless the user has changed the header themselves, in which case use (3).
columnHeader: (context) => {
// 3: the user overrode the header in the Layout — honour that
if (context.layoutSpecificHeaderName) {
return context.layoutSpecificHeaderName;
}
// 2: developer override for the Name column
if (context.columnType === 'tableColumn' && context.columnId === 'name') {
return 'JS Framework';
}
// 1: fall back to the AG Grid header
return context.colDefHeaderName;
}Hint
defaultHeaderNameis the resolved value that would be displayed if no function were provided- This is the Layout caption if one exists, otherwise the ColDef header
The function's context supports many different categories of column, including dynamically created ones.
columnHeader
(context: ColumnHeaderContext) => string- This demo shows how to change the Column Header programmatically. We change the Header for various types of columns (visible via different Layouts):
- For
tableColumnwe change 'Name' toJS Framework(seeTable Layout) - For
autoGroupColumnwe change the header to "My Row Group" (seeRow Grouped Layout) - For
tableColumnGroupwe change the header to "My Column Group" (seeColumn Group Layout) - For
pivotResultColumnwe add prefix of "Agg" to header (seePivot Layout) - For
pivotColumnGroupwe add prefix of "PC" to header (also seePivot Layout)
- For
- Switch between Layouts and see the different Headers
- Change the JavaScript Framework Column Header in the Layout Editor's Wizard — the function honours that user override via
layoutSpecificHeaderName
AG Grid Editable Header Names
AG Grid provides its own way to rename headers: setting headerNameEditable on a Column Definition (with ColumnHeaderEditModule) adds an Edit Column Name item to AG Grid's menus.
AdapTable does not integrate this feature, because AdapTable's own Column Header support already covers it and goes considerably further.
AdapTable Column Headers:
- are set per Layout, so the same Column can have a different caption in each Layout
- are saved in Adaptable State, together with the rest of the Layout
- can be shared with other users, as part of the Layout, via Team Sharing
- can be set at design-time in Initial State, at run-time in the Column Menu or the Layout Wizard, or programmatically via the Layout API
- can be computed by the
columnHeaderfunction, which covers Table Columns and Column Groups as well as Row Group, Pivot and Total Columns
A name edited in AG Grid, by contrast:
- is stored in AG Grid's Column State and Grid State rather than in the Layout, so it is not part of Adaptable State and cannot be shared via Team Sharing
- applies to every Layout, rather than to the Layout where it was set
- takes priority over the AdapTable header mechanism, hiding the Layout's
ColumnHeaderscaption and bypassing thecolumnHeaderfunction for that Column
Enabling AG Grid's feature would therefore replace a more capable mechanism with a more limited one, so AdapTable renames Column Headers through the Layout only.
Note
- AdapTable removes AG Grid's
Edit Column Nameitem from the Column Menu, the Context Menu and the Columns Tool Panel menu - Developers can add it back via
customColumnMenu/customContextMenu, but names edited that way bypass the Layout
Hint
To let users rename a Column at run-time, use the Change Caption Column Menu item, the Layout Wizard or the setColumnCaption function in Layout API