Kendoui Grid在单击"编辑"按钮时获取选定的行ID

Dea*_*Dan 4 kendo-ui kendo-grid

我有一个简单的网格,当使用JQuery单击编辑按钮时,我在收集PersonID时遇到了很多麻烦.我需要PersonID,因为我要将文件上传添加到内联编辑列,我想上传文件并将其与PersonID相关联.欢迎所有帮助:)

@(Html.Kendo().Grid<GridCustomPopupTemplate.Models.Person>().Name("Grid")
.DataSource(dataSource => dataSource
    .Ajax()
    .Model(model => model.Id(m => m.PersonID))
        .Read(read => read.Action("GetPersons", "Home"))
        .Update(up => up.Action("UpdatePerson", "Home"))
)

.Columns(columns =>
{
    columns.Bound(c => c.PersonID).Width(200);
    columns.Bound(c => c.Name);
    columns.Command(cmd => cmd.Edit());
})

.Pageable()
.Sortable()
.Editable(ed => ed.Mode(GridEditMode.InLine))
.Events(ev => ev.Edit("doOnRowSelect"))  
)



<script type="text/javascript">

function doOnRowSelect(e) {

     alert(The #PersonID# of the row which we are going to edit here....)

}

</script>
Run Code Online (Sandbox Code Playgroud)

Dea*_*Dan 5

我使用以下JavaScript实现了这一点:

$("body").on("click", "[role='row']", function (e) {

    var grid = $("#Grid").getKendoGrid();
    var item = grid.dataItem($(e.target).closest("tr"));
    alert(item.PersonID);

});
Run Code Online (Sandbox Code Playgroud)