【问题标题】:how to get key row selected in kendo ui grid如何在 kendo ui 网格中选择关键行
【发布时间】:2013-06-20 16:28:32
【问题描述】:

我编写这段代码是为了在 asp.net mvc 中使用剑道 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))

      ))   

我想当用户点击ViewDetails警报BrandId值列时,请帮助我。谢谢大家

【问题讨论】:

    标签: asp.net-mvc kendo-ui kendo-grid kendo-asp.net-mvc


    【解决方案1】:

    你只需要添加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>
    

    这里是Kendo Grid Custom Command的demo

    【讨论】:

      【解决方案2】:

      我也成功使用了这个:

      <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>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-09-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-15
        • 1970-01-01
        相关资源
        最近更新 更多