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

Kendo Grid Foreign Key Fields

1 Answer 553 Views
Grid
This is a migrated thread and some comments may be shown as answers.
KobusVisagie
Top achievements
Rank 1
KobusVisagie asked on 18 Oct 2012, 06:15 PM
Hi Everyone

I want to know if someone can help me out a bit, i am trying to use the foreign key columns, which is working just fine, accept, for some reason my kendo grid shows numeric text boxes instead of comboboxes, and i have followed the examples, but with no luck could i get them right :( attached is the code i am using

@{
        Html.Kendo().Grid<EasyAssets.Model.DTO.HomologationItemDTO>()
            .Name("itemsGrid")
            .Columns(c =>
                {
                    c.Bound(e => e.HomologationItemPriceID).ClientTemplate("<input id='#=ItemPriceID#' type='checkbox'/>").Template(t => "<input id='" + t.ItemPriceID + "' type='checkbox'/>").Title("").Width(30);
                    c.Bound(e => e.ItemPriceID).Filterable(false).Visible(false);
                    c.Bound(e => e.Item);
                    c.Bound(e => e.ItemPrice).Width(120);
                    c.ForeignKey(e => e.PriorityID, (System.Collections.IEnumerable)ViewData["priorities"], "id", "datatext").Title("Priority").Width(170);
                    c.ForeignKey(e => e.StatusID, (System.Collections.IEnumerable)ViewData["statuses"], "id", "datatext").Title("Status").Width(170);
                })
            .Editable(e => e.Mode(GridEditMode.InCell))
            .Sortable()
            .Pageable()
            .Filterable()
            .Scrollable()
            .Selectable(e => e.Mode(GridSelectionMode.Multiple))
            .AutoBind(false)
            .DataSource(e =>
                e.Ajax()
                .Batch(true)
                .ServerOperation(false)
                .PageSize(7)
                .Events(g => g.Error("ItemGridError"))
                .Model(m =>
                {
                    m.Field(f => f.ItemPrice).Editable(false);
                    m.Field(f => f.Item).Editable(false);
                    m.Id(i => i.HomologationItemPriceID);
                })
                .Read(r =>
                    {
                        r.Action("GetItems", "StockInspection");
                        r.Data("GetItemGridData");
                    }
                )
            )
            .Render();
    }

ViewData gets populated like this, the ModuleViewListDTO string(for values) and long(for ID's) properties
ViewData["priorities"] = _priorities = JsonConvert.DeserializeObject<ModuleViewListDTO>(GetOrPost("get", ApiUrl + "/api/Items?lookup=Priority", "")).data;
                ViewData["statuses"] = _statuses = JsonConvert.DeserializeObject<ModuleViewListDTO>(GetOrPost("get", ApiUrl + "/api/Items?lookup=ItemStatus", "")).data;

Attached is the results



Regards
Gregory

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 19 Oct 2012, 08:12 AM
Hi Gregory,

Could you please verify that you have added the GridForeignKey editor template file (available with the KendoUI for ASP.NET MVC distribution). You may find additional information about the editor templates here.

Greetings,
Rosen
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
KobusVisagie
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or