从Kendo Grid获取并提醒选择记录的ID

时间:2015-02-03 10:37:26

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

我在MVC应用程序中运行了kendo网格,在javaScript中运行了警报功能。我不能警惕工作;即所选记录的ID。我不确定我在代码中做错了什么!

的JavaScript

function DeleteFunctionNavigation(e) {

    e.preventDefaults();

    var entityGrid = $("#AllFunctionsGrid_02").data("kendoGrid");

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

    alert(selectedItem.Function_IDs);
}

function dataBound() {

}

Kendo Grid

<div class="_grid_block">

@(Html.Kendo().Grid<App.DAL.Model.GetAllFunction_SP_Map>()
 .Name("AllFunctionsGrid_02")
                 .Columns(column =>
                 {
                     column.Bound(c => c.Function_IDs);
                     column.Bound(c => c.FunctionName);
                     column.Bound(c => c.Hierarchy_Level);
                     column.Bound(c => c.ControllerName);
                     column.Bound(c => c.ActionName);
                     column.Command(command => command.Custom("View").Click("DeleteFunctionNavigation"));                       
                 })
 .HtmlAttributes(new { style = "height: 380px;" })
 .Editable(editable => editable.Mode(GridEditMode.PopUp))
 .Scrollable()
 .Filterable()
 .Groupable()
 .Sortable()
 .Selectable(selectable => selectable
 .Mode(GridSelectionMode.Single))
 .Pageable(pageable => pageable
 .Refresh(true)
 .PageSizes(true)
 .ButtonCount(5))
 .DataSource(dataSource => dataSource
 .Ajax()
 .Read(read => read.Action("GetAllFunctions", "SystemCore"))
 .Model(model => model.Id(c => c.Function_IDs))
)
.Events(events => events.DataBound("dataBound"))


)
</div> <!--end _grid_block-->

1 个答案:

答案 0 :(得分:1)

我创建了一个jsfiddle -

http://jsfiddle.net/mga6f/390/

代码: -

 $("#grid tr").click(function() {
     var entityGrid = $("#grid").data("kendoGrid");

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

     alert(selectedItem.id);

 });

使用上面的代码它工作正常..

我已尝试使用http://demos.telerik.com/aspnet-mvc/grid/selection上面给出的代码(此演示中的网格)并将下面的代码放在控制台中,然后选择行然后显示警报..

$("#rowSelection tr").click(function() {
    var entityGrid = $("#rowSelection").data("kendoGrid");

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

    alert(selectedItem.ShipCountry);

});