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

Kendo UI Grid<> columns.ForeignKey datasource

2 Answers 504 Views
Templates
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 14 Nov 2012, 08:18 PM
Hi, 

I was trying to create data grid, One column is Dropdownlist.  I want  to pass the dynamic  datasource from the Model. where Model is List<object>  . But the ForeignKey cloumn accepts only SelectList as second parameter. But I want  to make this dynamic i.e model.

See Below)

Current Functionality :

  columns.ForeignKey(s => s.FaceId, SelectList)

I need like   columns.ForeignKey(s => s.FaceId, x => x.FacesList)

Please suggest me to achieve this  functionality.

Thanks
Sunder

2 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 20 Nov 2012, 10:04 AM
Hello Chris,

The ForeignKey functionality provide you with the ability to display and edit a foreign key column with a human readable lookup collection instead of working with IDs.
The only requirement is to pass the collection with the Text/Value pairs at the time you define the Grid - it cannot be dynamically extracted from your model used for the Grid.

Please notice that your suggestion columns.ForeignKey(s => s.FaceId, x => x.FacesList) would mean that it is possible to have different collection for each record which is not true - same Text/Value pair collection is used for each of the records.

Kind regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Darron
Top achievements
Rank 1
answered on 15 Jan 2018, 10:22 PM

Instead of a foreignkey, I used bound columns with clienttemplates to look up the values to display based on the selected Integer from a hidden grid.

I used this approach instead of foreignkey when I'm storing integer values, displaying text based on that integer, and want to be able to edit/add new values to the list at will.

I used a hidden div, containing a grid for contacts.  OnEdit of the main grid (when it is the "Contacts" column), I unhide a fullscreen div to disable my main grid (opacity 60%) and unhide on top of that the div showing my Contacts grid.

In that contacts grid I use inline editing and have a custom button to "Pick" a row to be sent back to the main grid for use.  This button also re-hides the contacts grid and hides the shaded div, re-enabling use of the main grid.

Be sure to use autobind(false) on the main grid and then on the ondatabound of the lookup grid, do a read for the main grid.  If you have multiple hidden lookup grids, load them in series, loading the main grid last.  That ensures that the lookup grid/s (I actually have three) all are populated before the main grid tries to use them for lookups.

I use AJAX as the datasource for all four grids, and after editing/adding lines to any of the lookup grids, I refresh THAT grid prior to passing the selected value back to the main grid, so that the main grid displays the value correctly.  In my main grid I use inCell editing, and inline editing in all lookup grids.

Hope this helps.

 

Tags
Templates
Asked by
John
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Darron
Top achievements
Rank 1
Share this question
or