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

时间:2015-07-24 19:43:42

标签: 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>

2 个答案:

答案 0 :(得分:5)

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

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

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

});

答案 1 :(得分:2)

在所选网格行上使用grid.dataitem

var grid = $('#grdMyGrid').data('kendoGrid');
var selectedItem = grid.dataItem(grid.select());

使用OnChange(e)处理程序更新。

.OnChange(e=>e.OnChange("grdOnChange"))中,您可以存储和访问该项目。我确定网格更改将会激活另一行中的编辑按钮。

var selectedIndex=0;
function grdOnChange(e) {
   var selectedDataItem = e != null ? e.sender.dataItem(e.sender.select()) : null;

selectedIndex=selectedDataItem.MyModelID;

}

相关问题