Header renderers and renaming
How to put a button or a checkbox in a column header, add your own element, and let users edit the title in place (1.4.0). Without the keys below the header is exactly as before.
{ id: 'status', title: 'Status', headerRenderer: 'button',
headerRendererParams: { label: 'Complete all', onClick: ({ columnId }) => markAllDone(columnId) } }Header renderer (headerRenderer)
| Value | Meaning |
|---|---|
'button' | One button next to the title |
'checkbox' | One checkbox next to the title (on any column, separate from the selection column) |
HeaderAdapterFactory | Your own renderer: () => ({ mount(el, ctx), update?(ctx), destroy?() }) |
The control sits next to the title (position), and pressing or typing in it does not sort, drag, resize or open the column menu, because pointerdown, mousedown, click, dblclick and keydown stop at the control area.
button params (headerRendererParams)
| Key | Value | Default | Effect |
|---|---|---|---|
onClick | ({ columnId, event }) => void | required | On press; a throw is reported as an error event (callback-error) |
label | string | column title | Button text and aria-label |
position | 'start' · 'end' | 'end' | Before / after the title |
disabled | boolean or ({ columnId }) => boolean | false | Blocks it; sets disabled and aria-disabled, and onClick is not called |
editable | boolean | false | Rename the title (below) |
checkbox params
| Key | Value | Default | Effect |
|---|---|---|---|
onChange | (checked, { columnId }) => void | required | When it changes |
checked | boolean or ({ columnId }) => boolean | 'indeterminate' | false | Evaluated when drawn; 'indeterminate' is the partial look |
canCheck | ({ columnId }) => boolean | none | Returning false reverts the change |
position | 'start' · 'end' | 'start' | Before / after the title |
editable | boolean | false | Rename the title |
Values do not update by themselves after drawing. When your state changes, tell the grid with api.setHeaderRendererParams(id, { ...params, checked: true }). It is updateColumn(id, { headerRendererParams }), with the same validation and redraw (it needs the columns bundle).
Custom renderer
| Call | When |
|---|---|
mount(el, ctx) | Once, when first drawn; ctx is { columnId, column, api, params } |
update(ctx) | When the header is redrawn (width or order change, params change); the same element is moved to the new header cell so its state stays |
destroy() | When the column is removed, the renderer changes, horizontal virtualization takes it out of the window, or the grid is destroyed |
A throw in any of the three is reported as an error event (callback-error) and the header is still drawn.
Header dropdown (headerRenderer: 'dropdown')
Puts a button in the header that picks a value from a list. Your app receives the value and uses it to change a filter or a view.
{
id: 'team',
title: 'Team',
headerRenderer: 'dropdown',
headerRendererParams: {
options: [{ value: 'all', label: 'All' }, { value: 'dev', label: 'Dev' }],
value: 'all',
onSelect: ({ value }) => applyTeamFilter(value),
},
}Property (headerRendererParams) | Description |
|---|---|
options | An array of { value, label }, or a function called every time the list opens. Required. |
value | The chosen value (null means none). A new params object from setHeaderRendererParams takes its value. |
placeholder | Button text when nothing is chosen. Default is "선택" or "Select". |
onSelect | Receives ({ columnId, value, label }). If it throws, the grid keeps running and an error event fires. |
applyToTitle | When true the button reads "column title: chosen label" (title only before a pick) and the header title text is hidden. Default false. |
maxHeight | Maximum list height in px. Default 240; longer lists scroll inside. |
align | Horizontal alignment of the list ('start' or 'end'). Default 'start'. |
disabled | When true the button does nothing. |
position | Place it before ('start') or after ('end', default) the title. |
- Choosing also fires one
headerDropdownChanged { columnId, value, label }event. - Click the button, or press Enter, Space or Down, to open the list. Move with Up, Down, Home, End or the first letter, choose with Enter, close with Esc. A click outside closes it too.
- When there is no room below, the list flips above the button; on narrow screens it opens as a bottom sheet.
- Clicking the header does not sort. Redrawing the header (a width change and so on) closes an open list.
Keyboard
Controls add no tab stops (tabindex="-1"). With the header focused (focusHeader), Enter and Space press the built-in button or checkbox when the column has one and sorting is not enabled for it. On a sortable column Enter and Space sort (the control is pressed by mouse or touch).
Renaming the title
With titleEditable: true on a column (1.5.0, no header renderer needed) a double click on the title edits it in place, and F2 with the header focused opens it too. The earlier headerRendererParams: { editable: true } (alone, without a renderer, also works) still turns it on. It is off by default.
{ id: 'name', title: 'Name', titleEditable: true }| Action | Result |
|---|---|
| Double click, F2 | An input opens in place of the title (up to 120 characters) |
| Enter, losing focus | Commits: updateColumn(id, { title }), then headerRenamed { columnId, title } only when the title changed |
| Esc | Cancels |
| Same text | No change |
| Empty text | Rejected: Enter keeps the input open with an error mark, losing focus restores the old title |
beforeColumnChange hook | Called with type: 'update'; false keeps the title and sends no event |
| IME input | Enter and Esc are ignored while composing; Enter after the composition ends commits |
- Saving: a changed title goes into the
titleofgetColumnState(). It is present only for columns whose title differs from the initial one;setColumnState()andinitialStateapply it (throughbeforeColumnChange), andresetColumnState()restores the initial title. Details are in Save and restore state. - Elsewhere: export headers, header copy, find and the accessible name (aria) read the new title.
- Unchanged: sorting, dragging and resizing do not start from the input, and columns with a header renderer (button, checkbox, dropdown) keep working.
Computed title and tooltip (headerTitle, headerTooltipFor)
headerTitle: ({ columnId }) => string and headerTooltipFor are called when drawing and win over title and headerTooltip. If one throws, an error is reported and title or headerTooltip is used. They change the header text only; the column menu and exports still use title.
Merged header cells (headerSpan)
| Key | Meaning |
|---|---|
cols | How many neighbouring columns this header spans horizontally (1-64); the covered headers are not drawn |
rows | With headerGroups, how many header rows the column header occupies; more than the rows left means all the way down |
cols is ignored when a pinned column would be spanned or the last column would be passed. With grouped headers only rows applies. A value that is not an integer from 1 to 64 is an invalid-option.
Errors
| Situation | Error |
|---|---|
headerRenderer is not 'button', 'checkbox' or a function | invalid-option |
Required onClick or onChange is not a function, unknown key or value | invalid-option |
headerSpan value is not an integer from 1 to 64 | invalid-option |
headerTitle or headerTooltipFor is not a function | invalid-option |
Gallery example: header-button
Gallery example: header-checkbox
Gallery example: header-adapter-custom
Gallery example: header-rename
See also
- Resize, move and pin columns
- Runtime column changes:
updateColumn