Home > Mobile >  AgGrid: how do I get an instance of a custom cell renderer?
AgGrid: how do I get an instance of a custom cell renderer?

Time:05-26

I have a custom input cell renderer:

@Component({
  selector: 'my-ag-input-cell-renderer',
  template: `<my-input [(ngModel)]="_model"></my-input>`
})
export class InputCellRenderer implements ICellRendererAngularComp {
  public params: any = {};

  _model;

  agInit(params: any): void {
    this.params = params;

    this._model = params.value;
  }

  refresh(): boolean {
    return false;
  }

  getInputValue(): string {
    return this._model;
  }
}

Now I need a way to access getInputValue so I can retrieve a value from it.

I tried this.gridApi.getCellRendererInstances(), but it returns an array of DynamicAgNg2Component components and the method is not accessible through it.

Is there any way to do so? My ag-grid version is 24.1.0

CodePudding user response:

I recently ran into this problem. If you figure out which render it is within that list then call getFrameworkComponentInstance() it should return the component which you can then call your desired method.

More info

In my case, I used it on the a custom cellEditor but it should work similarly on the custom cellRenderer (swapping getCellEditorInstances() for getCellRendererInstances())

const cellEditor = this.gridApi.getCellEditorInstances()[0].getFrameworkComponentInstance();

cellEditor.myMethod()
  • Related