Grid Foreign Key Field sometime shows textbox

6 posts, 0 answers
  1. Victor
    Victor avatar
    4 posts
    Member since:
    Sep 2013

    Posted 11 Nov 2013 Link to this post

    Hi

    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
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2204 posts

    Posted 13 Nov 2013 Link to this post

    Hi Victor,

     
    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
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Victor
    Victor avatar
    4 posts
    Member since:
    Sep 2013

    Posted 13 Nov 2013 Link to this post

    Hi 

    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
  4. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2204 posts

    Posted 14 Nov 2013 Link to this post

    Hi 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");

    Kind Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  5. Xavier
    Xavier avatar
    28 posts
    Member since:
    Dec 2010

    Posted 23 Feb 2015 in reply to Vladimir Iliev Link to this post

    Hi Vladimir,

    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.







  6. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2204 posts

    Posted 24 Feb 2015 Link to this post

    Hi 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.

     
Back to Top