This is a migrated thread and some comments may be shown as answers.

this object is undefined or null

4 Answers 1305 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Arnie
Top achievements
Rank 1
Arnie asked on 26 Oct 2015, 03:25 PM

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

Sort by
0
Radoslav
Telerik team
answered on 28 Oct 2015, 08:00 AM
Hello Arnie,

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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Arnie
Top achievements
Rank 1
answered on 28 Oct 2015, 12:11 PM

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

 

 

0
Arnie
Top achievements
Rank 1
answered on 28 Oct 2015, 01:34 PM

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

0
Radoslav
Telerik team
answered on 29 Oct 2015, 06:45 AM
Hi 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
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
Arnie
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Arnie
Top achievements
Rank 1
Share this question
or