How to get the row of data when clicked?

2 posts, 0 answers
  1. Scott Smith
    Scott Smith avatar
    7 posts
    Member since:
    Oct 2010

    Posted 29 Nov 2017 Link to this post

    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

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 01 Dec 2017 Link to this post

    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.
Back to Top