ForeignKey column binding - Combobox editor for data editing

1 Answer 150 Views
Grid
Nguyen Ngoc
Top achievements
Rank 1
Iron
Nguyen Ngoc asked on 20 Jun 2021, 07:09 AM

Hi there,

I want to use Combobox editor for data editing, but it only used with local binding:

@(Html.KGrid(gridInfo).Columns(d=>d.ForeignKey(p => p.TableName, (System.Collections.IEnumerable)ViewData["TableNames"], "Id", "Name")))

@(Html.KGrid(gridInfo).Columns(d=>d.ForeignKey(p => p.TableName, ds => ds.Read(r =>r.Url("/sys/gridinfo/gettablenames")), "Id", "Name")))

If I use remote binding it show Dropdown List editor, I tried .EditorTemplateName("GridForeignKey") but it doesn't work.

Editor template GridForeignKey:

@model object
@(
 Html.Kendo().ComboBoxFor(m => m)
        .ValuePrimitive(true)
        .Filter("contains")
        .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
)
I hope to get help, thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi
Telerik team
answered on 23 Jun 2021, 11:21 AM

Hi Nguyyen,

I noticed that you have submitted the same query as a support ticket, as I've already answered your question in the ticket, I will post the same here in case someone else has the same question:

By default the grid will generate the editor template for a foreign bound column on the client. If you want to use a server editor you have to explicitly specify that by using the following overload:

columns.ForeignKey(p => p.CategoryID, ds=> ds.Read(r => r.Action("Categories", "Grid")), "CategoryID", "CategoryName", true)

That last boolean parameter specifies whether the server side editor should be used.

I hope this helps.

 

Regards,
Georgi
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.

Nguyen Ngoc
Top achievements
Rank 1
Iron
commented on 23 Jun 2021, 04:29 PM | edited

Thanks for your help, I solved the problem.
Tags
Grid
Asked by
Nguyen Ngoc
Top achievements
Rank 1
Iron
Answers by
Georgi
Telerik team
Share this question
or