I've a JavaScript class (myJqGrid) who has a property which is a jqGrid object. I want my jqGrid event callbacks to be able to use properties in my class (myJqGrid). How do I do this?
For example, in code at bottom, how would loadComplete refer to myJqGrid.selectedIds?
In my code I do:
let myGrid = new myJqGrid('someUrl/foo/bar', colNames, colModel);
myGrid.loadGrid(somePostDictionary);
I can't use this.selectedIds
, this
doesn't refer to my myJqGrid instance. And if I don't prefix selectedIds it can't resolve to the containing class' scope.
This is the class:
class myJqGrid {
grid; // the jqGrid object
selectedIds = [];
constructor(url, columnNames, model, gridId = 'jqGrid', pagerId ='jqGridPager') {
this.url = url;
this.gridHeader = columnNames;
this.gridModel = model;
this.gridId = gridId;
this.pagerId = pagerId;
}
loadGrid(postData) {
$('#grid').jqGrid('GridUnload');
this.grid = $('#' + this.gridId).jqGrid({
url: this.url,
datatype: "json",
// ...
loadComplete: function () {
// How do I refer to selectedIds of the parent class here?
// this.selectedIds is undefined, because `this` doesn't point to pdxJqGrid
}
}
}
}