I have an onChange function for my Kendo UI grid that reads as follows:
function onChange(arg) {
var selectedRow = this.select();
//Do something with selectedRow//
}
This function works perfectly when I run my code as a regular html page. However, when I copy my script and place in a "Script Editor" web part on SharePoint 2013, I receive an error stating that "this" is undefined or null. Any help on this issue would be truly appreciated. Thank You.
4 Answers, 1 is accepted
It seems that the context in the SharePoint case is different and you cannot use "this" keyword. However can you try getting the grid reference by its jQuery element representation. For example:
var
selectedRow = $(
"#gridID"
).data(
"kendoGrid"
).select();
Please give it try and let me know if it helps you.
Regards,
Radoslav
Telerik
Hello RadoSlav,
I tried the following:
var selectedRow =$("#grid").data("kendoGrid").select();
GetAnswers($("#grid").data("kendoGrid").dataItem(selectedRow).myField.toString());
but I still receive this error on the second line: "Unable to get property 'MyField' of undefined or null reference. This only happens the first time the grid is rendered. Once I click on a grid row, the onChange event works fine (even with the 'this' keyword. Thank You very much for our help.
Sincerely,
Arnie
RadoSlav,
The following code worked for me:
var selectedRow = this.select();
if(this.dataItem(selectedRow) != null) {
GetAnswers(this.dataItem(selectedRow).MyField.toString());
}
else {
selectedRow = $(this).select();
var myfield = selectedRow[0].table[0].cells[1].innerText;
GetAnswers(myfield);
}
This seems like a lot of work to get it to work in SharePoint. Is there a better way of getting this to work? I am still learning about the Kendo UI controls and any help is truly appreciated.
Thank You,
Arnie
Basically the select() method will return all selected rows in the grid. However if you do not have any selected row the select() method will return undefined and you cannot get the dataItem. You need to execute the code when the grid has a selected item.
Regards,
Radoslav
Telerik