I am defining a grid in which for the one of the columns I am using a cellRenderer to display an . While everything works fine I would like add the functionality where in if a user navigates/focuses on that cell ( defined by this column ) and hits ENTER the cursor/focus should make the input text editable. My knowledge of angular/ag-grid is very very basic, so please do excuse me if there are any fundamental flaws.
Here is my colDef
testField : ColDef {
headerName: 'testField',
field: ' testField',
cellRenderer: 'inputCellRenderer'
}
InputCellRenderer.ts
@Component({
selector: 'app-input-field',
template: '<mat-form-field>
<input mat-input type="text" [(ngModel)]="model" [(ngModelChange)}="HandleChange()">{{model}}</input>
</mat-form-field>
})
export InputRenderer extends ICellRendererAngularComp {
public model:string;
refresh(params : any): void {
// refresh logic
}
agInit(params : any) : void {
// initialize "model"
}
HandleChange(): void {
// handle model change logic
}
}
When a user focuses on a cell defined by "testField" and presses ENTER I want the cursor/focus to be on the input text field. If I make the column editable by adding
editable: true
it does not help as it does not pass the change in state to the rendered component.
I need to do something similar to this in the InputRenderer to enable focus
@Component({
selector: 'app-input-field',
template: '<mat-form-field>
<input #inputText mat-input type="text" [(ngModel)]="model" [(ngModelChange)}="HandleChange()">{{model}}</input>
</mat-form-field>
})
export InputRenderer extends ICellRendererAngularComp {
public model:string;
@ViewChild('inputText') textField : ElementRef
/* I THINK THIS NEEDS TO BE CALLED AS A CALLBACK FROM THE GRID CELL. GRID CELL SHOULD LISTEN to KEYPRESS/ENTER events and call this */
focusCallBack() {
this.textField.nativeElement.focus()
}
refresh(params : any): void {
// refresh logic
}
agInit(params : any) : void {
// initialize "model"
}
HandleChange(): void {
// handle model change logic
}
}
Any help on achieving this will be very helpful