Two questions...
First, as others have already mentioned, initialize the api grid link in onGridReady as follows.
onGridReady(params) { this.gridApi = params.api; }
Secondly, when ag-grid calls one of the handlers you provided (e.g. rowClicked), this no longer your instance of the corner component, so in your testClick() this.gridOptions === undefined .
To access the properties of your corner component in an AgGrid event callback, you must pass this via GridOptions.context as follows:
this.gridOptions = <GridOptions>{ context: {parentComponent: this}, ...other lines
AgGrid events (usually) return a reference to this context object in the Event parameters.
rowClicked(rowClicked: RowClickedEvent) { const localGridApiRef = rowClicked.context.parentComponent.gridApi;
Note: I'm not sure how you used testClick() but my rowClicked() would be interchangeable, I expect ...
Note 2 - GridApi is actually a RowClickedEvent property, so getting it through a context object, as shown in the figure, is redundant, but shows that access to the properties / methods of your corner component in the ag grid event can be done through the AgGridEvent context AgGridEvent .
source share