how to get key row selected in kendo ui grid

Pouya picture Pouya · Jun 24, 2013 · Viewed 22.7k times · Source

i write this code for create Grid with kendo Ui in asp.net mvc

  @(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))

      ))   

i want when user click on ViewDetails alert BrandId value Column, please help me.thanks all

Answer

Paritosh picture Paritosh · Jun 24, 2013

You just need to add javascript function.

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

Here is the demo of Kendo Grid Custom Command