Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to call Parent Scope function inside OnRefresh callback #880

Closed
karthikvt opened this issue Mar 9, 2018 · 5 comments
Closed

How to call Parent Scope function inside OnRefresh callback #880

karthikvt opened this issue Mar 9, 2018 · 5 comments

Comments

@karthikvt
Copy link

karthikvt commented Mar 9, 2018

I'm working on pivot table in Angular 5. I have a class named PivotTableComponent, I've defined pivotUI in one of the method in that class.

Couldn't call class function inside onRefresh callback function
`export class PivotTableComponent {
private rowArray = [];
private exclusionKPI = [];
createQuery(dimentions, kpi) {

}
loadData() {
$('#pivotTable').pivotUI(data,
{
rows: this.rowArray,
cols: ["KPI"], vals: ["Value"],
renderers: renderers,
aggregatorName: "Sum",
rendererName: "Table",
hiddenFromDragDrop: ["Value"],
exclusions: {
"KPI": this.exclusionKPI
},
onRefresh: function (data) {
this.rowArray = data.rows;
this.exclusionKPI = data.exclusions.KPI;
this.createQuery(data.rows, data.inclusions.KPI) // here, it throws error createQuery is not a function
}
});
}
}`

@karthikvt karthikvt changed the title Calling Parent Scope function inside OnRefresh callback How to call Parent Scope function inside OnRefresh callback Mar 9, 2018
@nicolaskruchten
Copy link
Owner

That's because your onRefresh function isn't bound to this, so this.createQuery isn't defined.

@karthikvt
Copy link
Author

I tried like this

‘onRefresh: this.refreshData(data);’ it never triggers that function. How we can do this ? Any suggestion ?

Thanks

@nicolaskruchten
Copy link
Owner

You'll need to create your callback function with a name, then bind it to the this object, then pass it in as the onRefresh parameter. Here's a bit of documentation about binding: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind

@nicolaskruchten
Copy link
Owner

Basically you'll have to do onRefresh: this.refreshData.bind(this)

@karthikvt
Copy link
Author

Thank you so much. It's working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants