Cell Editors
Create your own cell editor by providing a cell editor component.
The interface for the cell editor component is as follows:
The params object provided to the init method of the cell editor has the following interface:
Below is a simple example of Cell Editor:
Complementing Cell Editor Params
Again like cell renderers, cell editors can also be provided with additional parameters.
Do this using cellEditorParams like in the following example which will pass 'Ireland'
as the 'country' parameter:
Registering Cell Renderers with Columns
See the section registering custom components for details on registering and using custom cell renderers.
Keyboard Navigation While Editing
If you provide a cell editor, you may wish to disable some of the grids keyboard navigation. For example, if you are providing a simple text editor, you may wish the grid to do nothing when you press the right and left arrows (the default is the grid will move to the next / previous cell) as you may want the right and left arrows to move the cursor inside your editor. In other cell editors, you may wish the grid to behave as normal.
Because different cell editors will have different requirements on what the grid does, it is up to the cell editor to decide which event it wants the grid to handle and which it does not.
You have two options to stop the grid from doing it's default action on certain key events:
- Stop propagation of the event to the grid in the cell editor.
- Tell the grid to do nothing via the
colDef.suppressKeyEvent()callback.
Option 1 - Stop Propagation
If you don't want the grid to act on an event, call event.stopPropagation().
The advantage of this method is that your cell editor takes care of everything, good for
creating reusable cell editors.
The follow code snippet is one you could include for a simple text editor, which would stop the grid from doing navigation.
Option 2 - Suppress Keyboard Event
If you implement colDef.suppressKeyboardEvent(), you can tell the grid
which events you want process and which not. The advantage of this method of the previous
method is it takes the responsibility out of the cell editor and into the column
definition. So if you are using a reusable, or third party, cell editor, and the editor doesn't have
this logic in it, you can add the logic via configuration.
The params for suppressKeyboardEvent( ) are as follows:
Cell Editing Example
The example below illustrates:
- 'Gender' column uses a Component cell editor that allows choices via a 'richSelect' (ag-Grid-Enterprise only), with values supplied by complementing the editor parameters.
- 'Age' column uses a Component cell editor that allows simple integer input only.
- 'Mood' column uses a custom Component cell editor and renderer that allows choice of mood based on image selection.
- 'Address' column uses a Component cell editor that allows input of multiline text via a 'largeText'. Tab & Esc (amongst others) will exit editing in this field, Shift+Enter will allow newlines.
- 'Country' columns shows using 'richSelect' for a complex object - the cell renderer takes care of only rendering the country name.
Accessing Cell Editor Instances
After the grid has created an instance of a cell editor for a cell it is possible to access that instance.
This is useful if you want to call a method that you provide on the cell editor that has nothing to do
with the operation of the grid. Accessing cell editors is done using the grid API
getCellEditorInstances(params).
If you are doing normal editing, then only on cell is editable at any given time. For this reason
if you call getCellEditorInstances() with no params, it will return back the editing
cell's editor if a cell is editing, or an empty list if no cell is editing.
An example of calling getCellEditorInstances() is as follows:
The example below shows using getCellEditorInstances. The following can be noted:
- All cells are editable.
- First Name and Last Name use the default editor.
- All other columns use the provided
MySimpleCellEditoreditor. - The example sets an interval to print information from the active cell editor. There are three results: 1) No editing 2) Editing with default cell renderer and 3) editing with the custom cell editor. All results are printed to the developer console.
If your are using a framework component (detailed below), then the returned object
is a wrapper and you can get the underlying cell editor using getFrameworkComponentInstance()
Angular Cell Editing
It is possible to provide Angular cell editors's for ag-Grid to use if you are are using the Angular version of ag-Grid. See registering framework components for how to register framework components.
Your Angular components need to implement AgEditorComponent.
The ag Framework expects to find the agInit method on the created component, and uses it to supply the
cell params.
Angular Methods / Lifecycle
All of the methods in the ICellEditor interface described above are applicable
to the Angular Component with the following exceptions:
init()is not used. Instead implement theagInitmethod (on theAgRendererComponentinterface).destroy()is not used. Instead implement the AngularOnDestroyinterface (ngOnDestroy) for any cleanup you need to do.getGui()is not used. Instead do normal Angular magic in your Component via the Angular template.afterGuiAttached()is not used. Instead implementAfterViewInit(ngAfterViewInit) for any post Gui setup (ie to focus on an element).
All of the other methods (isPopup(), getValue(), isCancelBeforeStart(), isCancelAfterEnd() etc)
should be put onto your Angular component and will work as normal.
Example: Cell Editing using Angular Components
Using Angular Components in the Cell Editors, illustrating keyboard events, rendering, validation and lifecycle events.
React Cell Editing
It is possible to provide React cell editors for ag-Grid to use if you are are using the React version of ag-Grid. See registering framework components for how to register framework components.
React Props
The React component will get the 'Cell Editor Params' as described above as its React Props. Therefore you can access all the parameters as React Props.
React Methods / Lifecycle
All of the methods in the ICellEditor interface described above are applicable
to the React Component with the following exceptions:
init()is not used. Instead use the React props passed to your Component.destroy()is not used. Instead use the ReactcomponentWillUnmount()method for any cleanup you need to do.getGui()is not used. Instead do normal React magic in yourrender()method.
All of the other methods (isPopup(), isCancelBeforeStart(), isCancelAfterEnd(), afterGuiAttached() etc)
should be put onto your React component and will work as normal.
React Hooks
Please see here for information on using Hooks as Cell Editors.
Example: Cell Editing using React Components
Using React Components in the Cell Editors, illustrating keyboard events, rendering, validation and lifecycle events.
VueJS Cell Editing
It is possible to provide VueJS cell editors's for ag-Grid to use if you are are using the VueJS version of ag-Grid. See registering framework components for how to register framework components.
VueJS Parameters
The Grid cell's value will be made available implicitly in a data value names params. This value will be
available to
you from the created VueJS lifecycle hook. You can think of this as you having defined the following:
but you do not need to do this - this is made available to you behind the scenes, and contains the cells value.
VueJS Methods / Lifecycle
All of the methods in the ICellEditor interface described above are applicable
to the VueJS Component with the following exceptions:
init()is not used. The cells value is made available implicitly via a data field calledparams.getGui()is not used. Instead do normal VueJS magic in your Component via the VueJS template.afterGuiAttached()is not used. Instead implement themountedVueJS lifecycle hook for any post Gui setup (ie to focus on an element).
All of the other methods (isPopup(), getValue(), isCancelBeforeStart(), isCancelAfterEnd() etc)
should be put onto your VueJS component and will work as normal.
Example: Cell Editing using VueJS Components
Using VueJS Components in the Cell Editors, illustrating keyboard events, rendering, validation and lifecycle events.
A VueJS component can be defined in a few different ways (please see Defining VueJS Components for all the options), but in this example we're going to define our editor as a Single File Component:
Polymer Cell Editing
It is possible to provide Polymer cell editors's for ag-Grid to use if you are are using the Polymer version of ag-Grid. See registering framework components for how to register framework components.
Polymer Parameters
The ag Framework expects to find the agInit method on the created component, and uses it to supply the cell params.
Polymer Methods / Lifecycle
All of the methods in the ICellEditor interface described above are applicable
to the Polymer Component with the following exceptions:
init()is not used. Instead implement theagInitmethod.getGui()is not used. Instead do normal Polymer magic in your Component via the Polymer template.
All of the other methods (isPopup(), getValue(), destroy(), afterGuiAttached(), isCancelBeforeStart(), isCancelAfterEnd() etc)
should be put onto your Polymer component and will work as normal.
Example: Cell Editing using Polymer Components
Using Polymer Components in the Cell Editors, illustrating keyboard events, rendering, validation and lifecycle events.