Foreign Key Column - Display For

1 Answer 131 Views
Grid
Tracie
Top achievements
Rank 1
Tracie asked on 20 Oct 2022, 03:37 PM

Greetings,

I am new to Telerik syntax and was curious on how I can display a foreign key field in a table but I do not want to display it as a drop down list. Which is the default behavior in the editor templates. I basically just want to show a field from a table where the foreign key ID match with source table.

 

Thanks,

Tracie

1 Answer, 1 is accepted

Sort by
0
Stoyan
Telerik team
answered on 25 Oct 2022, 02:40 PM

Hi Tracie,

Depending on the exact requirement at hand you can utilize the approach suggested in the Grid's Foreign Key Column Binding Demo but either disabling the editing of the field

        .Model(model =>
        {
            model.Id(p => p.ProductID);
            model.Field(p => p.ProductID).Editable(false);
            model.Field(p => p.CategoryID).Editable(false);
        })

or configuring another Editor Template to handle its editing

        [UIHint("MyForeignKeyString")]
        public CategoryViewModel Category
        {
            get;
            set;
        }

I hope the information above is useful.

If any issues occur, please share some information about the configuration of the Grid on your side and the error messages that are getting thrown. Thank you in advance.

Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tracie
Top achievements
Rank 1
commented on 25 Oct 2022, 05:55 PM

Thanks for the reply. I did try to implement this and setting the field to not edit did give me my desired result. But then my issue was 'do I really want to load a collection of data when I just need the description on a foreign key id match'? That was my internal struggle. Also when I used foreign key with drop down list my available options for filter criteria were limited and the drop down list to search was enormous. I was able to find an alternative using View models and 'Include' statements within a controller that then turned my foreign key field into a bound column text box and I didn't need to use the collection anymore.
Tags
Grid
Asked by
Tracie
Top achievements
Rank 1
Answers by
Stoyan
Telerik team
Share this question
or