I have multiple kendo grid used inside a kendo tabstrip. I have same model for all the grid with some filter criteria.
Everything seems to be working fine except when i add or edit one grid and at the same time try to edit another grid, its foreign key is not showing its template. It shows textbox instead of dropdown.
Is this a known bug or is there any idea how to resolve this?
Regards
Victor
5 Answers, 1 is accepted
From the provided information it seems that the issue comes from having duplicated element ID attributes on the page - by default the DropDownList editor for the ForeignKeyColumn generate it's ID attribute from the current model property name. Possible solution is to generate unique IDs based on parent Grid model ID using custom editor template for the nested Grid - please check the example below:
@(Html.Kendo().Grid<OrderViewModel>()
.Name(
"Orders_#=EmployeeID#"
)
.Columns(columns =>
{
columns.ForeignKey(o => o.ShipID, (System.Collections.IEnumerable)ViewData[
"shipNames"
],
"ShipName"
,
"ShipID"
)
.EditorTemplateName(
"customFKCEditor"
)
.Width(200);
customFKCEditor.cshtml:
@model object
@(
//This editor should be used as custom editor template for the nested Grids only
Html.Kendo().DropDownListFor(m => m)
//Replace the 'EmployeeID' with your parent Grid ID
.HtmlAttributes(
new
{ id =
"DLL#=EmployeeID#"
})
.BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName(
""
) +
"_Data"
])
)
Regards,
Vladimir Iliev
Telerik
Thanks for your reply. You are right about duplicated id.
For the time being i just created separate view model for each grid which resolved my problem. I will give your solution try sometime.
I have found something else also. I am not sure if that is a bug on kendo side or it is a known behavior.
In my ViewModel class if I define UIHint as some other name (eg. UIHint["MyKendoDropDown"]) it still picks up the UIHint from the EditorTemplate which is named as GridForeignKey. So looks like it is looking for GridForeignKey in the editor first and make it as default UI ediot even though i have deifned UIHint as other editor.
Regards,
Victor
This behavior is expected and intended as the ForeignKeyColumn sets custom editor itself - in this case you can use the EditorTemplateName method to override the default editor ("GridForeignKey"):
columns.ForeignKey(p => p.EmployeeID, (System.Collections.IEnumerable)ViewData[
"employees"
],
"EmployeeID"
,
"Name"
).EditorTemplateName(
"CustomEditorName"
);
Vladimir Iliev
Telerik
My case is a little different, I have:
@(Html.Kendo().Grid<
ServiceDetailViewModel
>()<
br
> .Name("waste_details_" + serviceID)
@model object<
br
><
br
>@(Html.Kendo().DropDownList()<
br
> .Name("Reference_@serviceID")<
br
> .DataTextField("Text")<
br
> .DataValueField("Value")<
br
> .Filter(FilterType.Contains)<
br
> .OptionLabel("-please select-")<
br
> .ValuePrimitive(true)<
br
> .AutoBind(false)<
br
> .DataSource(source =><
br
> {<
br
> source.Read(read =><
br
> {<
br
> read.Action("SearchWaste", "Serveis").Data("filterSearchWaste");<
br
> })<
br
> .ServerFiltering(true);<
br
> })<
br
>)<
br
>
function filterSearchWaste() {<
br
> alert(detailID);<
br
> var filterInput = $("#Reference_@serviceID").data("kendoDropDownList").filterInput.val();<
br
> return {<
br
> text: filterInput+'|@serviceID'<
br
> };<
br
> }<
br
>
Can you explain me how to on Html.Kendo().DropDownList() I get Name property with ServiceID.
Thanks in advance.
Xavier.
As this thread is out of the original topic, may I kindly ask you to open a new support thread and elaborate more on the exact scenario that you have? In this way it is much easier to follow and concentrate on the particular issue which usually leads to its faster resolving.
Regards,
Vladimir Iliev
Telerik
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.