2013-06-24 13 views
7

napisać ten kod do tworzenia siatki z kendo Ui w ASP.NET MVCjak uzyskać klucz rząd wybrany w siatce kendo ui

@(Html.Kendo().Grid(Model) 
     .Name("Grid") 

     .Columns(columns => 
        { 
         columns.Bound(p => p.Id).Groupable(false).Visible(false); 
         columns.Bound(p => p.BrandName); 
         columns.Bound(p => p.BrandAbbr); 
         columns.Bound(p => p.SrcImage); 

         columns.Command(command => command.Custom("ViewDetails").Click("showDetails")); 
         }) 

    .ToolBar(toolbar => 
        { 
         toolbar.Custom().Action("Create","Users").Text("add");       
        } 
     ) 
     .Groupable() 
     .Pageable() 
     .Sortable() 
.Scrollable() 

     .Filterable() 
     .HtmlAttributes(new {style = "height:500px;"}) 
     .Selectable(selectable => selectable 
      .Mode(GridSelectionMode.Multiple) 
      .Type(GridSelectionType.Row)) 

     .DataSource(dataSource => dataSource 
            .Server()       
            .Model(model => model.Id(item => item.Id)) 

    )) 

chcę gdy użytkownik kliknie na ViewDetails alert BrandId wartość kolumny, proszę mi pomóc .thanks wszystkie

Odpowiedz

12

Wystarczy dodać funkcję javascript.

<script type="text/javascript"> 
    function showDetails(e) { 
     e.preventDefault(); 
     var dataItem = this.dataItem($(e.currentTarget).closest("tr")); 
     alert(dataItem.Id); //considering Id = BrandId 
    } 
</script> 

Oto demo Kendo Grid Custom Command

4

również użyłem to z powodzeniem:

<script type="text/javascript"> 

function showDetails(e) 
{ 
e.preventDefaults(); 
var grid = $("#Grid").data("kendoGrid"); 

    var selectedItem = grid.dataItem(grid.select()); 


//you can get the value of any column after that 

alert("Brand Id is : " + selectedItem.Id); 
alert("Brand Name is: " + selectedItem.BrandName); 

} 

</script> 
+3

'grid.select()' działa tylko jeśli siatka jest '.Selectable()' – Salar

Powiązane problemy