简体   繁体   English

Kendo ASP.Net MVC Datagrid如何在子行中获取父行ID

[英]Kendo ASP.Net MVC Datagrid how to get Parent Row Id in child rows

I have a parent hierarchy grid that have a child table for each of the parent row. 我有一个父层次结构网格,每个父行都有一个子表。 I have a custom command button in child table rows and want to access the parent row ID when I press that button. 我在子表行中有一个自定义命令按钮,并且想在按该按钮时访问父行ID。 Here is my code : 这是我的代码:

Parent Table : 父表:

    @(Html.Kendo().Grid<FsERP.Models.ParentModel>()
            .Name("gridParent")
            .Columns(columns =>
            {
                columns.Bound(p => p.ID).Hidden(true);
                columns.Bound(p => p.P_Column1).Width(180);
                columns.Bound(p => p.P_Column2).Width(180);
            })
            .DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .ServerOperation(false)
            .Model(model =>
            {
                model.Id(p => p.ID);
                model.Field(p => p.ID).Editable(false););
            })
            .PageSize(20)
            .Read(read => read.Action("EditingCustom_Read", "Parent"))
        ).ClientDetailTemplateId("childsTemplate")

Child Table Template : 子表模板:

        <script type="text/kendo" id="childsTemplate">

             @(Html.Kendo().Grid<FsERP.Models.ChildModel>()
                        .Name("gridChild")
                        .Events(e => e.DataBound("OnDataBound").Edit("OnEdit"))
                        .Columns(columns =>
                        {
                            columns.Bound(c => c.ID).Hidden(true);
                            columns.Bound(c => c.C_Column1).Width(180);
                            columns.Bound(c => c.C_Column2).Width(130);
                            columns.Command(command =>command.Custom("GetParentID").Click("showParentID")).Width(80);
    }).DataSource(dataSource => dataSource
            .Ajax()
            .Batch(true)
            .ServerOperation(false)
            .Model(model =>
            {
                model.Id(p => p.ID);
                model.Field(p => p.ID).Editable(false););
            })
            .PageSize(20)
            .Read(read => read.Action("EditingCustom_Read", "Child"))
        ).ToClientTemplate()
)

             </script>

Here is my javascript click method : 这是我的javascript click方法:

function showParentID(e) {

}

How would I alert the parent ID inside this showParentID() method. 我如何在showParentID()方法内提醒父ID。 Any help would be appreciable. 任何帮助将是可观的。

Thanks. 谢谢。

NOTE 注意

I dont want to send the parentID in parameter of the javascript method as I also need to access the event information. 我不想在javascript方法的参数中发送parentID,因为我也需要访问事件信息。

You can add parent ID field into your custom Command name like this: 您可以将父ID字段添加到自定义命令名称中,如下所示:

columns.Command(command => command.Custom("GetParentID_#=ID#")

Then inside your showParentID function retrieve the name of the button which has been triggered and split the ID after the underscore or whatever you rather. 然后在showParentID函数内部,检索已触发的按钮的名称,并在下划线或您想要的其他名称之后拆分ID。

Anyhow this is the POV and you could change this scenario in any form you think is better. 无论如何,这是POV,您可以以您认为更好的任何形式更改此方案。

The main hint here is to get access to parent id using #=ID# which is belong to the parent model 这里的主要提示是使用属于父模型的#=ID#来访问父ID

Please let me know if it helps or not 请告诉我是否有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM