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

DropDown in Grid

8 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jim
Top achievements
Rank 1
jim asked on 02 Feb 2015, 10:15 PM
I was following the demo for the Custom Editting
http://demos.telerik.com/aspnet-mvc/grid/editing-custom

And I did not get the Drop down as expected.    I saw the ID  and Name be replace in the column instead a drop down

I used the 
Columns.Bound(p => p.Category).ClientTemplate("#=Category.CategoryName#").Width(160);


The one thing I couldnt not figure out was in the Controller it defince the ViewData["categories"] = categories;

I could not figure out how that was wired to the Razor page.



8 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 04 Feb 2015, 09:34 AM
Hi Jim,

This collection is usually used to populate the columns.values array through the ForeignKey column builder, as shown in this demo.

Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
jim
Top achievements
Rank 1
answered on 04 Feb 2015, 06:27 PM
I tried dong that example as well.


In that case I just get the Id


.Columns(columns =>
{
    columns.Bound(p => p.Id);
    columns.ForeignKey(p => p.ApplicationId, (System.Collections.IEnumerable)ViewData["applications"], "Id", "Name")
            .Title("Application").Width(150);
 
    columns.Bound(p => p.Field).Width(100);
    columns.Bound(p => p.Criteria).Width(100);
    columns.Bound(p => p.ExclusionValue).Width(100);
    columns.Command(command => command.Destroy()).Width(90);
})


0
Alexander Popov
Telerik team
answered on 06 Feb 2015, 12:13 PM
Hi Jim,

The screenshots suggests that the default editor template for ForeignKey columns is not available. It usually resides in Views\Shared\EditorTemplates and is called GridForeignKey.cshtml. Here is the code as well: 
@model object
            
@(
 Html.Kendo().DropDownListFor(m => m)       
        .BindTo((SelectList)ViewData[ViewData.TemplateInfo.GetFullHtmlFieldName("") + "_Data"])
)


Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
jim
Top achievements
Rank 1
answered on 06 Feb 2015, 05:22 PM
Alexander,  I do have the template there and I put a breakpoint there to ensure it was hitting it.

So this is what I have:

The View:
@(Html.Kendo().Grid<HRIT.Models.UserExclusionViewModel>()
    .Name("grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.Id);
 
        columns.ForeignKey(p => p.ApplicationId, (System.Collections.IEnumerable)ViewData["applications"], "ApplicationId", "Name")
                .Title("Application").Width(150);
        columns.Bound(p => p.Field).Width(100);
        columns.Bound(p => p.Criteria).Width(100);
        columns.Bound(p => p.ExclusionValue).Width(100);
        columns.Command(command => command.Destroy()).Width(90);
    })
    .ToolBar(toolBar =>
        {
            toolBar.Create();
            toolBar.Save();
 
        })
    .Editable(editable => editable.Mode(GridEditMode.InCell))
    .Pageable()
    .Sortable()
    .Scrollable()
    .HtmlAttributes(new { style = "height:430px;" })
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .ServerOperation(false)
        .Events(events => events.Error("error_handler"))
        .Model(model =>
        {
            model.Id(p => p.Id);
            model.Field(p => p.Id).Editable(false);
            model.Field(p => p.ApplicationId).DefaultValue(1);
        })
        .PageSize(20)
        .Create(create   => create.Action("ExclusionPopup_Create", "Feed"))
        .Read(read       => read.Action("ExclusionPopup_Read", "Feed"))
        .Update(update   => update.Action("ExclusionPopup_Update", "Feed"))
        .Destroy(destroy => destroy.Action("ExclusionPopup_Destroy", "Feed"))
    )
)
  The Controller

public ActionResult Exclusion()
{
    PopulateApplications();
    return View();
}
And 
private void PopulateApplications()
{
 
    var dataContext = new HRITEntities1();
    var applications = dataContext.Applications
                .Select(a => new ApplicationViewModel
                {
                    Id = a.Id,
                    ApplicationId = a.Id,
                    Name = a.Name
                })
                .OrderBy(e => e.Name);
 
    ViewData["applications"] = applications;
    ViewData["defaultApplication"] = applications.First();
}
0
jim
Top achievements
Rank 1
answered on 06 Feb 2015, 06:21 PM
But this is interesting.  When I change the Application to 2, it will  display the name instead of the Id of it when I submit it
0
Alexander Popov
Telerik team
answered on 10 Feb 2015, 11:55 AM
Hello again Jim,

I reviewed the code snippets, but did not found any reason for showing regular input element instead of a DropDownList widget. Are there any JavaScript errors in the browser's console? Also, would you be able to share a runnable sample project where this occurs? That would allow us to observe it locally and suggest a solution.

Regards,
Alexander Popov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
jim
Top achievements
Rank 1
answered on 10 Feb 2015, 09:50 PM
Thanks Alexander. There was some javascript causing the error
0
Kelso
Top achievements
Rank 1
answered on 20 Feb 2015, 02:06 PM
AGAIN, you need to clear up your demos and documentation so that they match I wasted HOURS yesterday trying to get your demo code to work, Your tools are not saving me time when I have to spend an entire afternoon trying to make a demo work that is not even correct, nor complete. There is no transparency to the models and code you are using in your service to show examples for MVC, I do not care that you show it in Javascript in another place. I should not have to search all your demos and forums just to find that the demo is incorrect.
Tags
Grid
Asked by
jim
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
jim
Top achievements
Rank 1
Kelso
Top achievements
Rank 1
Share this question
or