Created
November 8, 2019 13:48
-
-
Save avallete/7b2fffb4f3443e21947d106d8d68a68e to your computer and use it in GitHub Desktop.
An example of how to create and use a cellEditorFactory to extend basic cellEditor components into ag-Grid
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {IAfterGuiAttachedParams, ICellEditorComp, ICellEditorParams, IComponent, Promise} from 'ag-grid-community'; | |
| export interface ISelectorCellEditor extends ICellEditorParams { | |
| highlightAllOnFocus?: boolean; | |
| } | |
| export interface ISCellEditor extends IComponent<ICellEditorParams>, ICellEditorComp { | |
| } | |
| export function selectorCellEditorFactory(cellEditor: new(...args: any[]) => (ISCellEditor)) { | |
| return class SelectorCellEditor extends cellEditor implements ICellEditorComp { | |
| private highlightAllOnFocus: boolean = false; | |
| constructor(props: any) { | |
| super(props); | |
| } | |
| public init(params: ISelectorCellEditor): void | Promise<void> { | |
| this.highlightAllOnFocus = !!params.highlightAllOnFocus; | |
| if (super.init) { | |
| return super.init(params); | |
| } | |
| return; | |
| } | |
| public afterGuiAttached(params?: IAfterGuiAttachedParams): void { | |
| const eGui = this.getGui(); | |
| const eInput = this.getGui().querySelector('input') as HTMLInputElement; | |
| if (super.afterGuiAttached) { | |
| super.afterGuiAttached(params); | |
| } | |
| if (this.highlightAllOnFocus) { | |
| eInput.select(); | |
| } | |
| } | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment