Select Id in ForeginKey column then displaying selected value

7 posts, 1 answers
  1. Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 16 Jul 2013 Link to this post

    Hello there,

    At the moment, I'm trying to create a grid where user is able to choose a product category in a first step, and then choose a product which belongs to the selected product category. All the cascading stuff is working perfectly using ForeignKey and custom editor.

    However, Foreignkey columns are binded to ID in model. So, when a selection is done, the displayed value is always the ID. I would like to display the value which match to the selected ID instead. I tried doing it through ClientTemplate, but it didn't work. I didn't find some custom property about it too.

    If require, I can post some code & screenshots.

    Thanks for answers :)
  2. Daniel
    Admin
    Daniel avatar
    2226 posts

    Posted 18 Jul 2013 Link to this post

    Hello Claude,

    I am not sure if I understand correctly the issue. The foreignkey column should automatically match the text to the value if a client template is not used as demonstrated in this demo. Is the value field still shown when the template is not added? If yes, could you provide the code you are using?

    Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 18 Jul 2013 Link to this post

    Sorry, double post
  4. Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 18 Jul 2013 Link to this post

    Hello,

    Yes, it's the behavior I would like to be able to implement. But as I need some cascading comboboxes in my grid, I've maybe mix up this behavior. Here some details.

    As data, I get a array which look like this:
    {FamilyId:PF01, FamilyName:SUPPORT DE COMMUNICATION}
    {FamilyId:PF02, FamilyName:BACHE}
    {FamilyId:PF03, FamilyName:CAISSON}

    In my grid, I setted up column like this:
    c.Bound(o => o.ProductFamilyId).Title("Famille de produit");

    The bound column use use the following editor :
    @(Html.Kendo().DropDownList()
        .Name("ProductFamilyId")
        .OptionLabel("Sélectionnez une catégorie professionnelle...")
        .DataValueField("FamilyId")
        .DataTextField("FamilyName")
        .DataSource(source => source
            .Read("GetAllProductFamiliesForComboBox", "ProductFamily")
        )
    )

    This way, when I select a value in a combobox and I save the grid row, the displayed value is FamilyId. Intending one is FamilyName.

    So, I tried to set up a ClientTemplate on column like this:
    c.Bound(o => o.ProductFamilyId)
        .Title("Famille de produit")
        .ClientTemplate("#=FamilyName#");

    But it didn't work. I just notice I didn't try to put ClientTemplate on the editor. I'll give it a try ASAP.
  5. Answer
    Daniel
    Admin
    Daniel avatar
    2226 posts

    Posted 22 Jul 2013 Link to this post

    Hello Claude,

    In that case I can suggest to use a ForeignKey column and override the default editor template with the column EditorTemplateName method e.g.

    columns.ForeignKey(o => o.ProductFamilyId,ViewData["ProductFamilies"] as SelectList).EditorTemplateName("myCascadingEditor");
    In case you are using PopUp editing you can specify the editor as usual with the UIHintAttribute. Regards,
    Daniel
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  6. Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 22 Jul 2013 Link to this post

    Perfect ! It works like a charm !

    Thank you very much for your help.
  7. Claude
    Claude avatar
    8 posts
    Member since:
    Jun 2013

    Posted 22 Jul 2013 Link to this post

    Thank you very much for your help ! It works like a charm now !
Back to Top