Hierarchical Grid - How to get and item value from the parent grid in server side variable?

2 posts, 0 answers
  1. Avinash
    Avinash avatar
    2 posts
    Member since:
    Apr 2012

    Posted 05 Apr 2013 Link to this post


    Hi,

    I have a simple master-detail implementation in a hierarchical grid. Everything works as expected if I pass the parent ID in following fashion

    @(Html.T4Grid<NTL.Target.BusinessEntities.Customer>("Grid", allColumns,"Customer")
    .ClientDetailTemplateId("template")
    .HtmlAttributes(new { style = "height:430px;" })
    .Events(events => events.DataBound("dataBound"))
    )

    <script id="template" type="text/kendo-tmpl">
     @(Html.Kendo().Grid<NTL.Target.BusinessEntities.Order>()
    .Name("Grid_#=CustomerID#")
    .DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(5)
    .Read(read => read.Action("GetList", "Order", new { customerID = "#=CustomerID#" }))
    )
    .Pageable()
    .Sortable()
    .ToClientTemplate()
    )
    </script>
    <script>
    function dataBound() {
    this.expandRow(this.tbody.find("tr.k-master-row").first());
    }
    </script>


    I intend to abstract binding of the grid completely, as shown above in the code that the data binding has been done in the extension method (T4Grid). Now when I try following it ends up in an error saying 'invalid template'. It throws that error because #=CustomerID# wasn't replaced.

    @(Html.T4Grid<NTL.Target.BusinessEntities.Customer>("Grid", allColumns,"Customer")
    .ClientDetailTemplateId("template")
    .HtmlAttributes(new { style = "height:430px;" })
    )
    <script id="template" type="text/kendo-tmpl">
    @{
    name="#=CustomerID#";
    gname = "Grid_#=CustomerID#";
    }
    @(Html.T4Grid<NTL.Target.BusinessEntities.Order>(gname, allColumns, "Order", new { customerID = name }))
    .ToClientTemplate()
    )

    What's the way of getting a field's value (server side) from the data source of the Parent Grid?

    Extension Method

    public static Kendo.Mvc.UI.Fluent.GridBuilder<T> T4Grid<T>(this HtmlHelper helper, string name, string allColumns, string controllerName, params object[] parameters)
    where T : class
    {
    List<ColumnAttributes> columns = BuildColumns(allColumns);

    return helper.Kendo().Grid<T>()
    .Name(name)
    .Columns(cols =>
    {
    if (columns != null)
    foreach (ColumnAttributes ca in columns)
    cols.Bound(ca.Name).Width(ca.Width).Title(ca.Title).Groupable(ca.Groupable);
    }
    )
    .Sortable()
    .Pageable()
    .Scrollable()
    .DataSource(dataSource => dataSource
    .Ajax()
    .PageSize(10)
    .Read(read => read.Action("GetList", "Order",parameters))
    );

    }
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 09 Apr 2013 Link to this post

    Hi Avinash,

     You cannot get the parent data item on the server-side when the grid is ajax bound. Binding occurs client-side and there is no way to get the item server-side. You may consider implementing server-side master/detail as shown in the <install location>\Kendo.Mvc.Examples\Areas\razor\Views\web\grid\serverhierarchy.cshtml example.

    Regards,
    Atanas Korchev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top