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

Select Id in ForeginKey column then displaying selected value

6 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Claude
Top achievements
Rank 1
Claude asked on 16 Jul 2013, 08:32 AM
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 :)

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 18 Jul 2013, 07:48 AM
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!
0
Claude
Top achievements
Rank 1
answered on 18 Jul 2013, 08:05 AM
Sorry, double post
0
Claude
Top achievements
Rank 1
answered on 18 Jul 2013, 08:07 AM
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.
0
Accepted
Daniel
Telerik team
answered on 22 Jul 2013, 06:58 AM
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!
0
Claude
Top achievements
Rank 1
answered on 22 Jul 2013, 09:58 AM
Perfect ! It works like a charm !

Thank you very much for your help.
0
Claude
Top achievements
Rank 1
answered on 22 Jul 2013, 10:02 AM
Thank you very much for your help ! It works like a charm now !
Tags
Grid
Asked by
Claude
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Claude
Top achievements
Rank 1
Share this question
or