Hi Jaime,
You could set the context of the event handler using the $.proxy method.
e.g.
var grid = $("#grid").data("kendoGrid");
grid.bind("change", $.proxy(grid_change, test));
Below you will find a small sample which demonstrates the above approach:
Regards,
Georgi
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
$("#grid").kendoGrid({
context : _service,
databound: _service.onDataBound,
request : _otherService.onRequest // Ooops wrong context
}
Perhaps the workaround should be encouraged in this situation.
$("#grid").kendoGrid({
context : _service,
databound: _service.onDataBound
}
export class Service {
onDataBound(e) {
this.doSomething(); // this points at the grid instance so doSomething can't be called
}
doSomething() { }
}
// grid javascript
_service = new Service();
$("#grid").kendoGrid({
...
databound: _service.onDataBound
...
}
The workaround so far is to add a base class to the service and register function calls slightly differently.
export abstract class ServiceBase {
bind(name) {
return this[name].bind(this);
}
}
export class Service extends ServiceBase { ... }
// Workaround grid code
$("#grid").kendoGrid({
...
databound: _service.bind('onDataBound')
...
}
When calling like that the correct context is available for the this keyword and e.sender can be used to access the grid.