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

[Solved] Getting Value of Parent GRid Column in Edit Template of Grid in Detail Template

3 Answers 547 Views
Grid
This is a migrated thread and some comments may be shown as answers.
IS
Top achievements
Rank 1
IS asked on 28 Mar 2015, 03:22 AM
I have a Parent Kendo Grid with a Child Grid in DetailTemplate. There is a column called InternalCode in Parent Grid that I want the value in Edit Template (popupEditorTemplate) of Child Grid in Detail Template. How can I do it? What is the Syntax?

@(Html.Kendo().Grid<UserStandardCodeType>().Name("grid")
.DataSource(dataSource => dataSource.Ajax().Read(read => read.Action("GetUserStandardCodesTypes_Ajax", "UserStandardCode")))
.Columns(columns =>
  {
      columns.Bound(usct => usct.InternalCode);
      columns.Bound(usct => usct.PresentationName);
      columns.Bound(usct => usct.Description);
  })
.ClientDetailTemplateId("client-template")
)

<script id="client-template" type="text/x-kendo-template">
    @(Html.Kendo().Grid<UserStandardCode>().Name("grid_#=Id#") 
    .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("popupEditorTemplate"))
          .Columns(columns =>
          {
              columns.Bound(usc => usc.InternalCode);
              columns.Bound(usc => usc.PresentationName);
              columns.Bound(usc => usc.Description);
              columns.Bound(usc => usc.IsEnabled);
              columns.Command(commands =>
              {
                  commands.Edit(); 
                  commands.Destroy(); 
              }).Title("Commands").Width(200);
          })
          .DataSource(dataSource => dataSource.Ajax()
              .Read(read => read.Action("GetUserStandardCodes_Ajax", "UserStandardCode", new { CodeTypeId = "#=Id#" }))
              .PageSize(2)
              .Model(model =>
              {
                  model.Field(usc => usc.CodeTypeId); 
                  model.Id(usc => usc.Id); 
              })
              .Create(create => create.Action("CreateUserStandardCode_Ajax", "UserStandardCode"))
              .Update(update => update.Action("UserStandardCodes_Ajax", "UserStandardCode"))
              .Destroy(destroy => destroy.Action("UserStandardCodes_Ajax", "UserStandardCode"))
          )
          .Pageable()
          .ToolBar(toolbar => toolbar.Create()) 
          .ToClientTemplate()
          )
</script>

Thanks

3 Answers, 1 is accepted

Sort by
0
IS
Top achievements
Rank 1
answered on 29 Mar 2015, 08:55 PM
Another issue I am having is if I have the same column names in both parent and grid in Detail Template, how I can differentiate between two columns?I am displaying a Field named "ID" in child grid but it is displaying the value from the Parent Grid.
Can someone tell me the correct syntax?
0
IS
Top achievements
Rank 1
answered on 30 Mar 2015, 03:45 PM
Anyone?
0
Boyan Dimitrov
Telerik team
answered on 31 Mar 2015, 05:02 PM

Hello,

One possible solution in order to implement such functionality is to have property of the detail grid model that points to the master grid current data item. In the example below the child grid model property EmployeeID. 

This way from the child grid PopUp template you can access the master grid model. For example you have following line of code in the  popupEditorTemplate view

<div>#:myTemplate(data)#</div>

and the function declared in on the grid page

function myTemplate(data) {
        return $("#masterGrid").getKendoGrid().dataSource.at(data.EmployeeID - 1).FirstName
    }

This function will use the EmployeeID value to find the dataItem of the master grid data source. 

 

Regards,
Boyan Dimitrov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Grid
Asked by
IS
Top achievements
Rank 1
Answers by
IS
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or