Search code examples
asp.net-mvc-4asp.net-mvc-5teleriktelerik-gridtelerik-mvc

sub grid in telerik not displaying records


I want to create parent - child grid. I can get parent grid as expected, but Datasource method is not calling for sub grid.
Can any one help me to find out solution?
Here is my code:

<div class="panel" style="float:left; width:87%;margin-left:12px">
        @(Html.Kendo().Grid<BuildingAssetEntities.Models.AssetDisplay>()
                .Name("ManageRecordgrid")
                .Columns(columns =>
                {
                    columns.Bound(c => c.BuildingName).Title("Building Name").Width(90);
                    columns.Bound(p => p.BuildingNo).Title("Building Number").Width(95);
                    columns.Bound(p => p.assetID).Title("QR").Width(50);
                })
                .ClientRowTemplate(
                            "<tr>" +

                            "<td width='90px'>#:checkNull(BuildingName)#</td>" +
                            "<td width='95px'>#:checkNull(BuildingNo)#</td>" +
                            "<td width='50px'>#:checkNull(assetID)#</td>" +                            
                            "</tr>")

                 .Pageable(Pageable => Pageable.Numeric(false)
                        .PageSizes(true))
                .Sortable()
                .Scrollable()
                .Filterable()
                .DataSource(dataSource => dataSource
                .Ajax()
                .Read(read => read.Action("GetManageRecordList", "Record"))
                .PageSize(20)
                .ServerOperation(false))
                 .ClientDetailTemplateId("template1")

        )

        <script id="template1" type="text/kendo-tmpl">

                @(Html.Kendo().Grid<BuildingAssetEntities.Models.AssetDisplay>()
                    .Name("grid_#=assetId#")
                    .Columns(columns =>
                    {
                        columns.Bound(c => c.BuildingName).Title("Building Name").Width(90);
                        columns.Bound(p => p.BuildingNo).Title("Building Number").Width(95);
                    })
                    .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("GetManageRecordSubList", "Record",new {assetId = "#=assetId#"}))
                    .ServerOperation(false))
                    .ToClientTemplate()
                )
        </script>
</div>

I am not get any idea, What is the issue. I am just getting parent grid, not sub grid.
Please give me your suggestion for the same.


Solution

  • I got the solution for this issue. I just changed my parent grid as below and it works as expected.

    <div class="panel" style="float:left; width:87%;margin-left:12px">
            @(Html.Kendo().Grid<BuildingAssetEntities.Models.AssetDisplay>()
                    .Name("ManageRecordgrid")
                    .Columns(columns =>
                    {
    
                        columns.Bound(c => c.BuildingName).Title("BuildingName").Width(90);
                        columns.Bound(c => c.BuildingNo).Title("BuildingNo").Width(95);
                    })
                    .Pageable(Pageable => Pageable.Numeric(false)
                            .PageSizes(true))
                    .Sortable()
                    .Scrollable()
                    .Filterable()
                    .DataSource(dataSource => dataSource
                    .Ajax()
                    .Read(read => read.Action("GetManageRecordList", "Record"))
                    .PageSize(20)
                    .ServerOperation(false))
                    .ClientDetailTemplateId("template1")
    
            )
    
            <script id="template1" type="text/kendo-tmpl">
    
                    @(Html.Kendo().Grid<BuildingAssetEntities.Models.AssetDisplay>()
                        .Name("grid_#=assetId#")
                        .Columns(columns =>
                        {
                            columns.Bound(c => c.BuildingName).Title("Building Name").Width(90);
                            columns.Bound(p => p.BuildingNo).Title("Building Number").Width(95);
                        })
                        .DataSource(dataSource => dataSource
                        .Ajax()
                        .Read(read => read.Action("GetManageRecordSubList", "Record",new {assetId = "#=assetId#"}))
                        .ServerOperation(false))
                        .ToClientTemplate()
                    )
            </script>
    </div>
    

    It was not expecting client template in parent grid.