本文介绍了如何使用 ASP.NET MVC 在 Kendo UI Grid 中实现 N 级嵌套层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ASP.NET MVC 在 Kendo UI Grid 中实现 N 级嵌套层次结构我可以实现特定数量的嵌套网格,但如何在 asp.net MVC 中使用特定数据实现 N 级嵌套网格

I am trying to implement N-level nested hierarchy in Kendo UI Grid using ASP.NET MVCi can implement specific number of Nested Grid but how to implement N-level nested Grid using a Specific Data in asp.net MVC

@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.EmployeeViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(e => e.FirstName).Width(110);
            columns.Bound(e => e.LastName).Width(110);
            columns.Bound(e => e.Country).Width(110);
            columns.Bound(e => e.City).Width(110);
            columns.Bound(e => e.Title);

        })
        .Sortable()
        .Pageable()
        .Scrollable()
        .ClientDetailTemplateId("template")
        .HtmlAttributes(new { style = "height:430px;" })
        .DataSource(dataSource => dataSource
            .Ajax()
            .PageSize(6)
            .Read(read => read.Action("HierarchyBinding_Employees", "Grid"))
        )
        .Events(events => events.DataBound("dataBound"))
)

<script id="template" type="text/kendo-tmpl">
    @(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.OrderViewModel>()
            .Name("grid_#=EmployeeID#")
            .Columns(columns =>
            {
                columns.Bound(o => o.OrderID).Width(70);
                columns.Bound(o => o.ShipCountry).Width(110);
                columns.Bound(o => o.ShipAddress);
                columns.Bound(o => o.ShipName).Width(200);
            })
            .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(5)
                .Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" }))
            )
            .Pageable()
            .Sortable()
            .ToClientTemplate()
    )
</script>
<script>
    function dataBound() {
        this.expandRow(this.tbody.find("tr.k-master-row").first());
    }
</script>

使用此代码我可以获得 1 个嵌套网格.

Using this code i can get 1 nested Grid.

请指导如何获得 N 级的剑道嵌套网格.谢谢

Please guide about getting N-Level of Kendo Nested Grids. Thanks

推荐答案

您可以使用 Kendo UI Grids 实现 N 级层次结构.

You can achieve N-level Hierarchy using Kendo UI Grids.

您的模板中应该有 ClientDetailTemplateId.这是示例.

You should have ClientDetailTemplateId in your templates. Here is the example.

<script id="clientTemplate" type="text/kendo-tmpl">
        @(Html.Kendo().Grid<TimeSheetManagement.Models.ClientView>()
                    .Name( "ClientGrid_#=Id#" )
                        .Columns( columns =>
            {
                columns.Bound( e => e.Name ).Title("Client Name");
                columns.Bound( e => e.Address ).Title( "Client Address" );
                columns.Bound( e => e.City ).Title( "Client City" );
                columns.Bound( e => e.State );
                columns.Bound( e => e.ZipCode );
                columns.Bound( e => e.CreatedDate );
                columns.Bound( e => e.CreatedBy );
                columns.Bound( e => e.UpdatedDate );
                columns.Bound( e => e.UpdatedBy );
                //columns.Bound( "" ).ClientTemplate( @Html.ActionLink( "Edit" , "Create" , new { clientId = "#=Id#" } , new { title = "Edit Client" } ).ToHtmlString() );
            } )
                .AutoBind( true )
                .DataSource( dataSource => dataSource
                    .Ajax()
                    .Read( read => read.Action( "GetClientsByProjectId" , "Client" , new { sProjectId = "#=Id#" } ) )
                )
                .ClientDetailTemplateId( "employeeTemplate" )
                .ToClientTemplate()
        )
</script>

这是子模板的实现.

<script id="employeeTemplate" type="text/kendo-tmpl">
        @(Html.Kendo().Grid<TimeSheetManagement.Models.EmployeeView>()
                    .Name( "EmployeeGrid_#=Id#" )
                .Columns( columns =>
                {
                    columns.Bound( e => e.EmployeeName );
                    columns.Bound( e => e.Address );
                    columns.Bound( e => e.City );
                    columns.Bound( e => e.State );
                    columns.Bound( e => e.ZipCode );
                    columns.Bound( e => e.PhoneNumber );
                    columns.Bound( e => e.Email );
                    columns.Bound( e => e.Designation );
                    columns.Bound( e => e.CreatedDate );
                    columns.Bound( e => e.CreatedBy );
                } )
                .AutoBind( true )
                .DataSource( dataSource => dataSource
                    .Ajax()
                    .Read( read => read.Action( "GetEmployeesByClientId" , "Employee" , new { sClientId = "#=Id#" } ) )
                )
                .ToClientTemplate()
        )
    </script>

这是输出.如果您还有其他问题,请告诉我.我希望这会帮助你.

Here is the output. Let me know if you have any more questions. I hope this will help you.

这篇关于如何使用 ASP.NET MVC 在 Kendo UI Grid 中实现 N 级嵌套层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 11:59