MVC Kendo UI Grid =自定义按钮无法返回选定的行ID [英] MVC Kendo UI Grid = Custom Button can't return selected row id

查看:167
本文介绍了MVC Kendo UI Grid =自定义按钮无法返回选定的行ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得选定的行ID,但它只是失败......我完全不知道这里发生了什么。
MVC HTML代码:

  @(Html.Kendo()。Grid(Model)
.Name (grid)
.HtmlAttributes(new {style =margin-top:5px})
.Columns(c =>
{
c.Bound => model.mgID);
c.Command(com => {com.Custom(Edit)。Click(Edit);});
})
.Pageable()
.Sortable()
.Selectable()
.DataSource(d => d
.Ajax()
.PageSize(20)
.Model(model => model.Id(i => i.mgID))
.Read(r => r.Action(Manage_Read,Manage))
.Destroy(o => o.Action(Manage_Destroy,Manage))


Javascript代码:

 函数Edit(){

var grid = $(#grid)。data(kendoGrid);
var row = grid.select();
var selectedRowIndex = row.index(); //返回-1
var dataItem = grid.dataItem(row); //返回未定义

}

请告诉我,什么是如果您只需要获取包含点击的编辑按钮的行的dataItem,那么您就错过了它。

可以使用:

 函数编辑(e){
var dataItem = this.dataItem($(e.target) .closest( TR));
}

注意:


  • 的环境中点击事件这个网格
  • 在同一上下文中,
  • e.target 是您的按钮,因此我们寻找最接近表格行。


I want to get the selected row "ID" but it just failed... and i have totally no clue what is happening here. MVC HTML Code :

@(Html.Kendo().Grid(Model)
    .Name("grid")
    .HtmlAttributes(new { style = "margin-top: 5px" })
    .Columns(c =>
    {
        c.Bound(model => model.mgID);
        c.Command(com => { com.Custom("Edit").Click("Edit");});
    })
    .Pageable()
    .Sortable()
    .Selectable()
    .DataSource(d => d
        .Ajax()
        .PageSize(20)
        .Model(model => model.Id(i => i.mgID))
        .Read(r => r.Action("Manage_Read", "Manage"))
        .Destroy(o => o.Action("Manage_Destroy", "Manage"))
    )
)

Javascript Code :

    function Edit() {

        var grid = $("#grid").data("kendoGrid");
        var row = grid.select();
        var selectedRowIndex = row.index();   //Return "-1"
        var dataItem = grid.dataItem(row);    //Return "Undefined"

    }

Please tell me, what am i miss out??

解决方案

If all you need is get the dataItem of the row containing the clicked "Edit" button, you can use:

function Edit(e) {
    var dataItem = this.dataItem($(e.target).closest("tr"));
}

NOTE:

  • in the context of click event this is the grid.
  • in that same context e.target is your button, so we look for the closest table row.

这篇关于MVC Kendo UI Grid =自定义按钮无法返回选定的行ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆