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

How to get the row of data when clicked?

1 Answer 201 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Scott Smith
Top achievements
Rank 2
Scott Smith asked on 29 Nov 2017, 05:20 PM

In the MVC definition of the grid, I added

  .Events(e=>e.Change("gridChange"))

 

and then in the script, 

 function gridChange(){
                    var grid = $("#grid").data("kendoGrid");
                    var selectedItem = grid.dataItem(grid.select());
                    alert("Data is: "+ selectedItem.toString());
                }

Run, click on row?  Alert Data is: [Object object]

 

If I change it to    alert("Data is: "+ selectedItem[0]);

 

Run, click on row? Alert Data is: undefined.  There are 5 items in each row array, need to list them out, looking for any examples on how to do this in MVC, thanks!

Brad

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 01 Dec 2017, 08:42 AM
Hello Brad,

The dataItem will contain all of the properties of the records bound to the Grid. In your first code snippet, you are trying to display the object and in the second you are trying to use the object as an array. If you need to access a property of the dataItem that contains a collection, please use the following syntax instead:
dataItem.YourFieldNameOfTheCollection[index]

If further assistance is needed, please share the model that you are binding to your Grid, so we can have a better idea of the exact scenario.

Looking forward to your reply.


Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Scott Smith
Top achievements
Rank 2
Answers by
Konstantin Dikov
Telerik team
Share this question
or