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

Detail Grid with ForeignKey EditorTemplate

1 Answer 142 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gregor
Top achievements
Rank 1
Gregor asked on 27 Jun 2014, 11:11 AM
Hi!

I'm having a master grid which has a detail grid. In both grids I use an EditorTemplate on a ForeignKeyColumn.
The DropDown is correctly shown on the first grid, but not on the detail grid.
When I debug I can see that the template code is only called for the master grid.
I do not get any errors in console.

In the screenshot attached you can see the dropdown correctly appearing in the master grid but not in the detail grid.

Master Grid (Line 28-30):
01.@(Html.Kendo().Grid<LFG.Model.Domain.Appointment>(Model)
02.                .Name("AppointmentGrid")
03.                .Columns(columns =>
04.                {
05.                    columns.Command(p =>
06.                    {
07.                        p.Custom(LFG.Web.Constants.BtnDetail).Click("onEdit").Text(LFG.Web.Constants.BtnDetailDisplayText);
08.                        p.Edit().Text(LFG.Web.Constants.BtnEditDisplayText)
09.                            .CancelText(LFG.Web.Constants.BtnCancelDisplayText)
10.                            .UpdateText(LFG.Web.Constants.BtnUpdateDisplayText);
11.                    }).Width(LFG.Web.Constants.GridColumnWidthSmall);
12.                    columns.Command(p =>
13.                    {
14.                        p.Custom(LFG.Web.Constants.BtnPrintInformation).Click("onPrint_info").Text(LFG.Web.Constants.BtnPrintInformationDisplayText);
15.                        p.Custom(LFG.Web.Constants.BtnPrintGardenInformation).Click("onPrint_ginfo").Text(LFG.Web.Constants.BtnPrintGardenInformationDisplayText);
16.                    }).Title("Verständigung").Width(LFG.Web.Constants.GridColumnWidthSmall);
17.                    columns.Command(p =>
18.                    {
19.                        p.Custom(LFG.Web.Constants.BtnPrintDeliveryNote).Click("onPrint_deliverynotes").Text(LFG.Web.Constants.BtnPrintDeliveryNoteDisplayText);
20.                        p.Custom(LFG.Web.Constants.BtnPrintInvoice).Click("onPrint_invoice").Text(LFG.Web.Constants.BtnPrintInvoiceDisplayText);
21.                    }).Title("Stappel").Width(LFG.Web.Constants.GridColumnWidthSmall);
22.                    columns.Command(p =>
23.                    {
24.                        p.Custom(LFG.Web.Constants.BtnPrintPackingList).Click("onPrint_packinglist").Text(LFG.Web.Constants.BtnPrintPackingListDisplayText);
25.                    }).Title("Ausdrucke").Width(LFG.Web.Constants.GridColumnWidthSmall);
26.                    columns.Bound(p => p.ID).Hidden();
27.                    columns.Bound(p => p.Date).Width(LFG.Web.Constants.GridColumnWidthSmall);
28.                    columns.ForeignKey(o => o.RouteID, new SelectList(ViewBag.Routes, "ID", "Text"))
29.                        .Width(LFG.Web.Constants.GridColumnWidthLarge)
30.                    .EditorTemplateName("ForeignKeyDropDown");
31.                    columns.Bound(p => p.Description).Width(LFG.Web.Constants.GridColumnWidthNormal);
32.                    columns.Bound(p => p.TotalUnits).Width(LFG.Web.Constants.GridColumnWidthSmall);
33.                    if (User.IsInRole(LFG.Web.Filters.LFGRoles.ADM) ||
34.                        User.IsInRole(LFG.Web.Filters.LFGRoles.SADM))
35.                    {
36.                        columns.Command(command =>
37.                        {
38.                            command.Destroy().Text(LFG.Web.Constants.BtnDeleteDisplayText);
39.                        }).Width(LFG.Web.Constants.GridColumnWidthSmall);
40.                    }
41.                })
42.                .ToolBar(toolbar => toolbar.Create().Text(LFG.Web.Constants.BtnCreate))
43.                .Editable(editable => editable.Mode(GridEditMode.InLine)
44.                    .DisplayDeleteConfirmation(LFG.Web.Constants.ConfirmDelete))
45.                .Pageable(p => p.Enabled(Model.Count() > LFG.Web.Constants.GridPageSize))
46.                .Sortable()
47.                .Selectable()
48.                .Scrollable(s => s.Height(LFG.Web.Constants.GridPageSize * LFG.Web.Constants.GridLineHeight))
49.                .DataSource(dataSource => dataSource
50.                    .Ajax()
51.                    .PageSize(LFG.Web.Constants.GridPageSize)
52.                    .Events(events => events.Error("grid_error_handler"))
53.                    .ServerOperation(false)
54.                    .Model(model =>
55.                    {
56.                        model.Id(p => p.ID);
57.                    })
58.                    .Create(update => update.Action("_Update", "Appointment"))
59.                    .Update(update => update.Action("_Update", "Appointment"))
60.                    .Destroy(update => update.Action("_Destroy", "Appointment")))
61.                    .Events(e => e.DataBound("onRowBound"))
62.                .ClientDetailTemplateId("detailsTemplate")
63.            )

Detail Grid (Line14-16):
01.<script id="detailsTemplate" type="text/kendo-tmpl">
02.    @(Html.Kendo().Grid<LFG.Model.Domain.AppointmentDetail>()
03.            .Name("detailsGrid_#=ID#")
04.            .Columns(columns =>
05.            {
06.                columns.Command(command =>
07.                {
08.                    command.Edit().Text(LFG.Web.Constants.BtnEditDisplayText)
09.                        .UpdateText(LFG.Web.Constants.BtnCancelDisplayText)
10.                        .CancelText(LFG.Web.Constants.BtnCancelDisplayText);
11.                }).Width(LFG.Web.Constants.GridColumnWidthSmall);
12.                columns.Bound(o => o.ID).Hidden();
13.                columns.Bound(o => o.AppointmentID).Hidden();
14.                columns.ForeignKey(o => o.RouteDetailID, new SelectList(ViewBag.RouteDetails, "ID", "Text"))
15.                    .Width(LFG.Web.Constants.GridColumnWidthNormal)
16.                    .EditorTemplateName("ForeignKeyDropDown");
17.                columns.Bound(o => o.Start).Width(LFG.Web.Constants.GridColumnWidthNormal);
18.                columns.Bound(o => o.End).Width(LFG.Web.Constants.GridColumnWidthNormal);
19.                columns.Bound(o => o.TotalUnits).Width(LFG.Web.Constants.GridColumnWidthNormal);
20.                if (User.IsInRole(LFG.Web.Filters.LFGRoles.ADM) ||
21.                    User.IsInRole(LFG.Web.Filters.LFGRoles.SADM))
22.                {
23.                    columns.Command(commands =>
24.                    {
25.                        commands.Destroy().Text(LFG.Web.Constants.BtnDeleteDisplayText);
26.                    }).Width(LFG.Web.Constants.GridColumnWidthSmall);
27.                }
28.            })
29.            .ToolBar(toolbar => toolbar.Create().Text(LFG.Web.Constants.BtnCreate))
30.            .Scrollable(c => c.Height(250))
31.            .Pageable()
32.            .Selectable()
33.            .Sortable()
34.            .Editable(e => e.Mode(GridEditMode.InLine))
35.            .DataSource(source => source
36.                .Ajax()
37.                .Read("_ReadDetail", "Appointment", new { parentID = "#=ID#" })
38.                .Create("_UpdateDetail", "Appointment", new { parentID = "#=ID#" })
39.                .Update("_UpdateDetail", "Appointment", new { parentID = "#=ID#" })
40.                .Destroy("_DestroyDetail", "Appointment")
41.                .Model(model =>
42.                {
43.                    model.Id(id => id.ID);
44.                    model.Field(f => f.RouteDetailID).Editable(false);
45.                    model.Field(f => f.TotalUnits).Editable(false);
46.                })
47.                .ServerOperation(false))
48.            .ToClientTemplate()
49.    )
50.</script>

ForeignKeyDorpDown.cshtml (located in Shared folder)
@if (ViewData["SelectIndex"] != null && ViewData["SelectIndex"] is int)
{
    int i = ((int)ViewData["SelectIndex"]) >= 0 ? ((int)ViewData["SelectIndex"]) : 0;
    var list = (SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"];
    @(Html.Kendo().DropDownListFor(x => x)
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
    .AutoBind(true)
    .DataValueField("Value")
    .DataTextField("Text")
    .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
    .SelectedIndex(i)
    )
}
else
{
    @(Html.Kendo().DropDownListFor(x => x)
    .Name(ViewData.TemplateInfo.GetFullHtmlFieldName(""))
    .AutoBind(true)
    .OptionLabel(LFG.Web.Constants.PleaseSelect)
    .DataValueField("Value")
    .DataTextField("Text")
    .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
    )
}
@Html.ValidationMessageFor(x => x)

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 30 Jun 2014, 07:13 AM
Hi,

I posted my reply in the support ticket on the same topic. For convenience, I am pasting it below:

From the code it seems that the property used for the foreignkey column is declared as not editable in the model:
model.Field(f => f.RouteDetailID).Editable(false);
and therefore the grid will not create an editor for the column. Please check if enabling editing for the field resolves the problem.

Regards,
Daniel
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
Gregor
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or