Skip to content

Instantly share code, notes, and snippets.

@avallete
Created November 8, 2019 13:48
Show Gist options
  • Select an option

  • Save avallete/7b2fffb4f3443e21947d106d8d68a68e to your computer and use it in GitHub Desktop.

Select an option

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
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