This is a migrated thread and some comments may be shown as answers.
dynamic Grid
1 Answer 16 Views
This is a migrated thread and some comments may be shown as answers.
FranckSix
Top achievements
Rank 1
FranckSix asked on 07 Jan 2020, 04:42 PM

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!

1 Answer, 1 is accepted

Sort by
0
Tsvetomir
Telerik team
answered on 09 Jan 2020, 12:48 PM

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.
Tags
Grid
Asked by
FranckSix
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Share this question
or