Jose
Jose

Reputation: 1819

cellRendererParams Ag-Grid 19 and Angular 6. Call function of my component

I have in my Ag-grid column a column in which I have inserted a component, that pusal calls me to a function of my controller.

I get to my controller without problem, but when trying to call another function of my controller, I can not, because when I put this, it does not refer to my controller, but to the ag-grid component.

// COMPONENT

this.columnDefs = [{
  headerName: '',
  width: 50,
  cellRendererFramework: ActionCellRendererComponent,
  cellRendererParams: {
    icon: 'fa-trash',
    action: this.downloadAttachmentAction
  }
},



downloadAttachmentAction(params: any) {
   this.otherFunction() <-- I can not do the functions of my controller. with "this" as it refers to ag-grid
}

otherFunction(){
}

Upvotes: 0

Views: 4631

Answers (1)

Ritesh Waghela
Ritesh Waghela

Reputation: 3727

This is a context issue, the downloadAttachmentAction is called by ag grid and hence the context is ag-gird instance, what you need to do is change the context when that function is invoked, bind function help us do this, change how the downloadAttachmentAction is being used from:

    action: this.downloadAttachmentAction

to

    action: this.downloadAttachmentAction.bind(this)

Upvotes: 4

Related Questions