nested grid

May 30, 2014 at 2:48 PM
I looked for an example of nested grid, but couldn't find one. I experimented with it and got it working. I thought I share the code in case some body wants to do the same thing:
    <div >
    @helper RenderPartColumn(Request r, Log l)
    {
        <form method="POST" action="@Url.RouteUrl(new { controller = "Report", action = "Index" })" >
            <div  style="overflow-y: scroll; height:300px;">@*scrollable div*@
           @Html.Grid(Model.GetPartsByModelName(r.OrderNumber)).Columns(columns =>
           {
               columns.Add(c => c.Name).Titled("Part Name").Sortable(true).SetWidth(30).Filterable(true);
               columns.Add(c => c.PartType).Titled("Type").Sortable(true).SetWidth(30).Filterable(true);

           })
           </div>
        </form>
    }
   @Html.Grid(Model.LogByOrderNumber()).Columns(columns =>
    {
        columns.Add(c => c.Request.ModelName).Encoded(false).Titled("Model Name").Sortable(true).SetWidth(60);
        columns.Add(c => c.Request.ProjectName).Encoded(false).Titled("Project Name").Sortable(true).SetWidth(60);
        columns.Add(c => c.Request.OrderNumber).Encoded(false).Sanitized(false).Titled("Part Information").RenderValueAs(a => RenderPartColumn(a.Request, a.Log).ToHtmlString());

    }).WithPaging(20)
    </div>
LogByOrderNumber() gives me data for the 1st level grid and GetPartsByModelName() gives me data for 2nd level grid. I use RenderValueAs() to render the second grid. You have to put the inner grid in some kind of html tag like div to make it work.

Thanks for looking at my post.