Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

telerik-grid onRowSelect how to get id?

Hi i am new in asp.net mvc and telerik controls. How can i get o.Id value when i click on row?

 <%= Html.Telerik().Grid(Model)                    
                    .Name("RolesGrid")
                    .DataKeys(keys => keys.Add(o => o.Id))                               
                    .Selectable()                    
                    .Columns(columns =>
                    {
                        columns.Bound(o => o.Name);
                        columns.Bound(o => o.Description);

                    })
                    .Pageable()                       
                    .ClientEvents(events => events                    
                    .OnRowSelect("onRowSelect"))

             %>

in js code:

 function onRowSelect(e)   {
        var ordersGrid = $('#RolesGrid').data('tGrid');  
        var row = e.row;
        var dataItem = ordersGrid.dataItem(row);
        alert(dataItem);
    }

But dataItem is null and there is no id value in generated html file. Thanks and sorry for my bad english

like image 374
Sanja Melnichuk Avatar asked Nov 28 '22 19:11

Sanja Melnichuk


1 Answers

So after all i have the best way to get id is:

  1. bind onRowSelect function to your grid
  2. write next code in onRowSelect

    var dataItem = jQuery('#MyGridId').data('tGrid').dataItem(e.row);     
    alert(dataItem['Id']);
    

    dataItem is a map witch have all properties of grid model so you get all you want

Thats all, thanks

like image 66
Sanja Melnichuk Avatar answered Dec 18 '22 04:12

Sanja Melnichuk