@libregrid/column-header-edit
v1.3.5
Published
Editable column and group header names for AG Grid Community — part of LibreGrid
Downloads
75
Maintainers
Readme
@libregrid/column-header-edit
Let users rename column and column-group headers. Edited names are stored in column state so your application can save and restore a user’s preferred labels.
Install
npm install "ag-grid-community@^36.2.0" @libregrid/column-header-editRequires ag-grid-community >=36.1.0 <37 as a peer dependency. The
"Edit Column Name" menu entry requires @libregrid/menu
(ColumnMenuModule). Register both modules for the UI shown below.
Usage
In a browser TypeScript project, add a grid container before running the code:
<div id="grid" style="height: 400px"></div>import { ModuleRegistry, AllCommunityModule, createGrid } from 'ag-grid-community';
import { ColumnMenuModule } from '@libregrid/menu';
import { ColumnHeaderEditModule } from '@libregrid/column-header-edit';
ModuleRegistry.registerModules([AllCommunityModule, ColumnMenuModule, ColumnHeaderEditModule]);
createGrid(document.querySelector<HTMLElement>('#grid')!, {
columnDefs: [
{ field: 'name', headerNameEditable: true },
{
headerName: 'Region',
headerNameEditable: true,
children: [{ field: 'country' }],
},
],
rowData: [{ name: 'Alice', country: 'UK' }],
});Mark any column or column group headerNameEditable: true and its column menu
gains an Edit Column Name item. The editor opens over the header cell.
Apply behavior and saved state
The default editor applies header changes as users type. Set
columnHeaderEdit: { applyMode: 'deferred' } in the grid options to show
Apply and Cancel buttons. Set suppressColumnHighlighting: true in that
object to disable editing highlights.
Edited names take priority over headerValueGetter and headerName.
Save column state with api.getColumnState() and restore it with
api.applyColumnState({ state }). The overridden label is held in the state's
headerName field; setting it to null restores the definition's label.
Group labels are stored in column-group state. See the
header editing guide for examples.
API
| Export | Purpose |
| ------------------------- | ------------------------------------------------------------------------- |
| ColumnHeaderEditModule | Registers the feature (moduleName: 'ColumnHeaderEdit'). |
| ColumnHeaderEditService | The colHeaderEditSvc bean — editor, highlight state, menu contribution. |
Learn more
- LibreGrid README — full package list and quick start
@libregrid/menu— column menu this feature plugs into
Angular
Use the same column definitions and grid options with ag-grid-angular.
Register the modules shown above through provideLibreGrid from
@libregrid/angular. See the
Angular setup for a complete component and bootstrap example.
License
MIT — see LICENSE and NOTICE. LibreGrid is an independent project and is not affiliated with, endorsed by, or sponsored by AG Grid Ltd.
