I just updated to release '2015.1.318' and a Grid that was working fine with several ForeignKey columns bound to Guid and selectlists is now not working. I add and update In-Line on the grid. Now when I CREATE a new Entity inline - the editor displays all the data perfectly but the data sent to the server does not include the values selected for the ForeignKey columns. These are sent as Empty Guids i.e.00000000-0000-0000-0000-000000000000.
Note - when I UPDATE an existing entity it all works fine, the problem is only when I CREATE\INSERT.
The code for the Grid is below and the EditorTemplate for the ForeignKey column is also there.
Grid
<script type=
"text/javascript"
>
function gridEntityAssignments_CreateData() {
return
{
assignedTo:
"@(assignedTo)"
,
assignedToOid:
"@(assignedToOid)"
,
};
}
</script>
@*All Required*@
@Html.Hidden(
"IsAssignments"
, isAssignments)
@Html.Hidden(
"AssignmentsAssignedToOid"
, assignedToOid)
@Html.Hidden(
"AssignmentsAssignedTo"
, assignedTo)
<div style=
"width: 100%"
>
@(Html.Kendo().Grid<Mallon.AssignedTo.Models.ViewGridAssignment>()
.Name(
"GridEntityAssignments"
)
.AutoBind(isAssignments)
//if false - Report not loaded on page initialise
.HtmlAttributes(
new
{ @
class
=
"ignore"
})
.ToolBar(toolbar =>
{
toolbar.Create().HtmlAttributes(
new
{ @
class
=
"dfw-ignoreDirtyLink"
});
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Scrollable(s => s.Height(
"auto"
))
.Columns(columns =>
{
columns.Bound(p => p.Oid).Visible(
false
);
columns.ForeignKey(p => p.UserOid, (System.Collections.IEnumerable)ViewData[
"AssignmentUsers"
],
"Value"
,
"Text"
).EditorTemplateName(
"GridForeignKeyWithSelect"
).Title(
"User"
);
columns.ForeignKey(p => p.AssignmentTypeOid, (System.Collections.IEnumerable)ViewData[
"AssignmentTypes"
],
"Value"
,
"Text"
).EditorTemplateName(
"GridForeignKeyWithSelect"
).Title(
"Type"
);
columns.Bound(p => p.Info).EditorTemplateName(
"GridTextArea"
);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
})
.DataSource(dataSource => dataSource
.Ajax()
.AutoSync(
false
)
.Model(model =>
{
model.Id(p => p.Oid);
model.Field(p => p.Oid).DefaultValue(Guid.Empty);
})
.Events(e => e.Error(
"handleAjaxError"
))
.Destroy(update => update.Action(
"Assignments_GridDelete"
,
"Assignment"
))
.Update(update => update.Action(
"Assignments_GridUpdate"
,
"Assignment"
))
.Create(update => update.Action(
"Assignments_GridCreate"
,
"Assignment"
).Data(
"gridEntityAssignments_CreateData"
))
.Read(read => read.Action(
"Assignments_GridRead"
,
"Assignment"
,
new
{ assignedToOid = assignedToOid }))
)
)
</div>
Editor Template
@model
object
@(
Html.Kendo().DropDownListFor(m => m)
.BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName(
""
) +
"_Data"
]).OptionLabel(
"Please Select"
)
)
10 Answers, 1 is accepted
I believe the problem is that the dropdownlists associated with the ForeignKey columns are not firing their select event when I select my selection. If I select an item then select another different item then the correctly selected data gets sent.
Any idea how to fix this?
Alright this functionality is broken. The first select event on the ForeignKey dropdownlist is not updating the model values. I have to explicitly set dropDownList values using the onSave event as shown below. Telerik why dosnt this work?
Heres the updates code with the Save event.
@(Html.Kendo().Grid<Mallon.AssignedTo.Models.ViewGridAssignment>()
.Name(
"GridEntityAssignments"
)
.AutoBind(isAssignments)
//if false - Report not loaded on page initialise
.HtmlAttributes(
new
{ @
class
=
"ignore"
})
//Save Event is required because Inline eding with DropDownLists (ForegnKeys) dosnt seem to pick up the first select
//event. So even when I change\select the value the selected value is not populating the model with the data. This
//is only a problem on the first select.
.Events(events => events.Edit(
"onEdit_GridEntityAssignments"
).Save(
"onSave_GridEntityAssignments"
))
.ToolBar(toolbar =>
{
toolbar.Create().HtmlAttributes(
new
{ @
class
=
"dfw-ignoreDirtyLink"
});
})
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Scrollable(s => s.Height(
"auto"
))
.Columns(columns =>
{
columns.Bound(p => p.Oid).Visible(
false
);
columns.ForeignKey(p => p.UserOid, (System.Collections.IEnumerable)ViewData[
"AssignmentUsers"
],
"Value"
,
"Text"
).EditorTemplateName(
"GridForeignKeyWithSelect"
).Title(
"User"
);
columns.ForeignKey(p => p.AssignmentTypeOid, (System.Collections.IEnumerable)ViewData[
"AssignmentTypes"
],
"Value"
,
"Text"
).EditorTemplateName(
"GridForeignKeyWithSelect"
).Title(
"Type"
);
columns.Bound(p => p.Info).EditorTemplateName(
"GridTextArea"
);
columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);
})
.DataSource(dataSource => dataSource
.Ajax()
.AutoSync(
false
)
.Model(model =>
{
model.Id(p => p.Oid);
model.Field(p => p.Oid).DefaultValue(Guid.Empty);
})
.Events(e => e.Error(
"handleAjaxError"
))
.Destroy(update => update.Action(
"Assignments_GridDelete"
,
"Assignment"
))
.Update(update => update.Action(
"Assignments_GridUpdate"
,
"Assignment"
))
.Create(update => update.Action(
"Assignments_GridCreate"
,
"Assignment"
).Data(
"gridEntityAssignments_CreateData"
))
.Read(read => read.Action(
"Assignments_GridRead"
,
"Assignment"
,
new
{ assignedToOid = assignedToOid }))
)
)
Javascript events:
//Used to set the initial value for ForeignKey dropDownLists
function
onEdit_GridEntityAssignments(e) {
if
(e.model.isNew()) {
$(
"#GridEntityAssignments tbody [data-role=dropdownlist]"
).each(
function
() {
var
ddl = $(
this
).data(
"kendoDropDownList"
);
if
(ddl) {
ddl.select(0);
}
})
}
}
//This is required because Inline eding with DropDownLists (ForegnKeys) dosnt seem to pick up the first select
//event. So even when I change\select the value the selected value is not populating the model with the data. This
//is only a problem on the first select.
function
onSave_GridEntityAssignments(e) {
$(
"#GridEntityAssignments tbody [data-role=dropdownlist]"
).each(
function
() {
var
ddl = $(
this
).data(
"kendoDropDownList"
);
if
(ddl) {
var
v = ddl.value();
var
p = ddl.list.attr(
'id'
).replace(
'-list'
,
''
);
if
(p) e.model.set(p, v);
}
})
}
Hello Tyler,
We have fixed this issue and it is already included in our service pack release (2015.1.408).
I would like to apologize for any inconveniences caused.
Regards,
Boyan DimitrovTelerik
See What's Next in App Development. Register for TelerikNEXT.
Hello Terry,
Could you please try to set valuePrimitive option to true for the DropDownList editor of the foreign key column and let us know how that worked?
Regards,Boyan Dimitrov
Telerik by Progress
columns.ForeignKey(c => c.GenerationTypeID, (System.Collections.IEnumerable)@ViewBag.gentypes, "Value", "Text").Title("Generation");
The property should be set to the editor template and not in the column definition. You should have a GridForeignKey editor template within your Views/Shared/EditorTemplates folder with the DropDownList:
@(
Html.Kendo().DropDownListFor(m => m)
.BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
.ValuePrimitive(true)
)
Hope this helps.
Regards,
Konstantin Dikov
Telerik by Progress
Konstantin - that worked. Thanks.
For anyone else reading this. I didn't make any changes to my view. What Konstantin showed me to change was the GridForeignKey Editor Template.
For me it is still not working
@(Html.Kendo().Grid<OSH.Domain.Models.PhoneNumber.AppPhoneNumberItem>()
.Name("PhoneNumberGrid")
.Columns(columns =>
{
columns.Bound(e => e.PhoneNumber);
columns.Bound(e => e.Description);
//columns.Bound(e => e.PhoneNumberTypeId);
//columns.Bound(e => e.PhoneCarrierId);
columns.ForeignKey(e => e.PhoneNumberTypeId, (System.Collections.IEnumerable)ViewData["PNType"], "PhoneNumberTypeId", "PhoneNumberType")
.Title("Phone Number Type");
columns.ForeignKey(e => e.PhoneCarrierId, (System.Collections.IEnumerable)ViewData["PhoneCarrier"], "PhoneCarrierId", "PhoneCarrier")
.Title("Phone Carrier");
columns.ForeignKey(e => e.LocationId, (System.Collections.IEnumerable)ViewData["Location"], "LocationId", "LocationName")
.Title("Location");
//columns.Bound(e => e.LocationId);
columns.Command(command => { command.Edit().Text(" "); command.Destroy().Text(" "); });
})
.ToolBar(toolbar => { toolbar.Create(); })
.Editable(editable => editable.Mode(GridEditMode.InLine))
.Sortable()
.Pageable()
.Scrollable()
.ColumnMenu()
.Filterable()
.HtmlAttributes(new { style = "height:420px;", data_value_primitive = "true" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model => model.Id(p => p.PhoneCarrierId))
.Read(read => read.Action("readPhoneNumber", "Admin"))
.Create(update => update.Action("CreatePhoneNumber", "Admin"))
.Update(update => update.Action("EditPhoneNumber", "Admin"))
.Destroy(update => update.Action("DeletePhoneNumber", "Admin"))
.Events(events => events.Error("error_handler").Sync("sync_handler"))
)
please help.
Could you please elaborate if you have included the GridForeignKey.cshtml template in the Views/Shared/EditorTemplates folder as suggested in my previous post?
If the template is available and if you are populating correctly the data collection that you are passing to the ForeignKey column, everything should be working correctly.
Regards,
Konstantin Dikov
Progress Telerik