Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to achieve N-level nested hierarchy in Kendo UI Grid using ASP.NET MVC

I am trying to implement N-level nested hierarchy in Kendo UI Grid using ASP.NET MVC i 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>

Using this code i can get 1 nested Grid.

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

like image 385
John Sheedy Avatar asked May 26 '14 05:05

John Sheedy


3 Answers

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

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>

Here is the implementation for child template.

<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.
enter image description here

like image 127
Ranjith Avatar answered Nov 08 '22 04:11

Ranjith


Create partial views for each of your nested grids. The partial view grids will each have a ClientDetailTemplate.

like image 40
David Avatar answered Nov 08 '22 04:11

David


I think is no way to do something like this because suck kind of data (tree) are displayed using treeview plugins or something like that , this should be more clearly , this is why even they have this kind of ui component.

like image 1
Nic Avatar answered Nov 08 '22 03:11

Nic