This is a migrated thread and some comments may be shown as answers.

Grid / Hierarchy, the function of inner grid define in read method is not being called at all

1 Answer 100 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 28 Dec 2016, 09:53 PM
Outer Grid:
@(Html.Kendo().Grid(Model)
                .Name("assetTypeGrid")
                .Columns(columns =>
                {
                    columns.Bound(a => a.Type).ClientTemplate(@"<img src='/Content/Images/Pins/#:data.Type#' style='height: 32px; weight: 32px;' />").Width(100);
                    columns.Bound(a => a.Description).Title("Name").Width(200);
                    columns.Bound(a => a.Tabs).Title("Available Tab(s)").Width(200);
                    columns.Bound(a => a.AssetTypeId).Title("").Filterable(false).Sortable(false)
                        .ClientTemplate(createLink).Width(100);
                })
                .Sortable()
                .Pageable(pageable => pageable
                .ButtonCount(5))
                .Filterable(ftb => ftb.Mode(GridFilterMode.Row))
                .ClientDetailTemplateId("template")
                .DataSource(dataSource => dataSource
                .Ajax()
                .PageSize(20)
                .ServerOperation(false))
                )
Inner Grid:
<script id="template" type="text/kendo-tmpl">
       @(Html.Kendo().Grid<CIMSDashboard.ViewModels.AssetTemplateViewModel>()
       .Name("grid_#=Name#")
       .Columns(columns =>
       {
           columns.Bound(o => o.Types).Width(110);
           columns.Bound(o => o.Name).Width(110);
           columns.Bound(o => o.Description).Width(110);
       })
 
       .DataSource(dataSource => dataSource
           .Ajax()
           .PageSize(10)
           .Read(read => read.Action("GetAssetTemplates", "AccessRetriever", new { templateName = "Pipe" }))
        )
        .Pageable()
        .Sortable()
        .ToClientTemplate()
       )
   </script>
Script:
<script type="text/javascript">
        $(document).ready(function () {
 
            function dataBound() {
                this.expandRow(this.tbody.find("tr.k-master-row").first());
            }
 
        });
 
    </script>
Read Function:
public static List<AssetTemplateViewModel> GetAssetTemplates(string templateName)
        {
            using (MiniProfiler.Current.Step("Getting Asset template Details"))
            {
                var result = new List<AssetTemplateViewModel>();
                using (var context = ProfiledContext())
                {
                    var query = from ta in context.tblTemplate_Assets
                            join at in context.tblAssetTypes on ta.AssetType equals at.Name
                            join atl in context.tblLink_AssetTypeToTemplate_Assets on ta.keyTempAssetID equals atl.fk_Template_AssetID
                            where atl.fk_AssetType == templateName
                                select new AssetTemplateViewModel()
                                {
                                    Types = at.Logo,
                                    Name = ta.Name,
                                    Description = ta.Description
                                };
 
                    if (query.Any())
                    {
                        foreach (var q in query)
                        {
                            result.Add(q);
                        }
                    }
                }
 
                return result;
            }
        }

 

The above read function is not being called.. am I missing something?? the layout of inner grid is coming perfectly, its all about data is not being displayed.. it is not reaching my break point in AccessRetriver at all...   I've attached pictures of my output.. pls help me. Thank you in advance.

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 30 Dec 2016, 10:39 AM
Hi Bryan,

Make sure that the Read method of the nested Grid is using signature similar to the following. The GetData() method implements the logic for returning the records from the data source.


public ActionResult GetAssetTemplates(string templateName, [DataSourceRequest] DataSourceRequest request)
{
    return Json(GetData()
        .Where(item => item.TemplateName == templateName)
        .ToDataSourceResult(request));
}


In case you would like a live example on how you can implement Grid with hierarchical structure please refer to the example below.




Regards,
Viktor Tachev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Bryan
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or