dynamic Grid

2 posts, 0 answers
  1. FranckSix
    FranckSix avatar
    19 posts
    Member since:
    Feb 2011

    Posted 07 Jan 2020 Link to this post

    Hi all,

    I am trying to make an HtmlHelper to create sub grids by passing an ISubGridBuilder which will contain the construction detail of my sub grid.

    Example:

    public interface ISubGridBuilder
    {
       string ActionName { get; }
       string ControlerName { get; }
       void BuildColumns(GridColumnFactory<dynamic> gcf);
    }
     
    public static MvcHtmlString SubGridClient(this HtmlHelper html, ISubGridBuilder builder)
    {
       return html.Kendo().Grid<dynamic>()
          .Name("detailGrid")
          .Navigatable(n => n.Enabled(true))
          .Selectable(s => s
             .Mode(GridSelectionMode.Single)
             .Type(GridSelectionType.Row))
          .Columns(gcf =>
          {
             gcf.Bound("ParentId").Hidden(true);
             gcf.Bound("Id").Hidden(true);
             builder.BuildColumns(gcf);
          })
          .DataSource(d => d
             .Ajax()
             .Model(m =>
             {
                m.Id("Id");
                m.Field("ParentId", typeof(int));
             })
             .Read(r => r.Action(builder.ActionName, builder.ControlerName, new {Id = "#=ParentId#" }))
             .PageSize(3)
          )
          .Pageable(p => p
             .AlwaysVisible(false)
             .PageSizes(new[] { 3 })
          )
          .Events(e => e.Change("function(e) { onChange(e)}"))
          .ToClientTemplate();
    }


    The problem is that at runtime I get a reference error:

    VM17183:3 Uncaught ReferenceError: ParentId is not defined
        at Object.eval [as tmpl0] (eval at compile (kendo.all.js:234), <anonymous>:3:12352)
        at Object.eval (eval at compile (kendo.all.js:234), <anonymous>:3:185)
        at d (jquery.min.js:2)
        at HTMLAnchorElement.<anonymous> (kendo.all.js:64799)
        at HTMLTableElement.dispatch (jquery.min.js:3)
        at HTMLTableElement.r.handle (jquery.min.js:3)

    How can I add the ParentId parameter on the routeValues for the controller call.

    Thank you!

  2. Tsvetomir
    Admin
    Tsvetomir avatar
    757 posts

    Posted 09 Jan 2020 Link to this post

    Hi Francis,

    I have investigated the provided code snippets and I have noticed that the ParentID is a field that is available for the detail grid. However, the template is evaluated at the parent-level, therefore, the parent grid does not have such a field. Could you try alternating the declaration as follows:

             .Read(r => r.Action(builder.ActionName, builder.ControlerName, new {Id = "\\#=ParentId\\#" }))
    

    Let me know in case the issue persists.

     

    Regards,
    Tsvetomir
    Progress Telerik

    Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
Back to Top