DropDown in Grid

9 posts, 0 answers
  1. jim
    jim avatar
    11 posts
    Member since:
    Jun 2012

    Posted 02 Feb 2015 Link to this post

    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.



  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1444 posts

    Posted 04 Feb 2015 Link to this post

    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.

     
  3. jim
    jim avatar
    11 posts
    Member since:
    Jun 2012

    Posted 04 Feb 2015 in reply to Alexander Popov Link to this post

    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);
    })


  4. Alexander Popov
    Admin
    Alexander Popov avatar
    1444 posts

    Posted 06 Feb 2015 Link to this post

    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.

     
  5. jim
    jim avatar
    11 posts
    Member since:
    Jun 2012

    Posted 06 Feb 2015 in reply to Alexander Popov Link to this post

    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();
    }
  6. jim
    jim avatar
    11 posts
    Member since:
    Jun 2012

    Posted 06 Feb 2015 in reply to jim Link to this post

    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
  7. Alexander Popov
    Admin
    Alexander Popov avatar
    1444 posts

    Posted 10 Feb 2015 Link to this post

    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.

     
  8. jim
    jim avatar
    11 posts
    Member since:
    Jun 2012

    Posted 10 Feb 2015 in reply to Alexander Popov Link to this post

    Thanks Alexander. There was some javascript causing the error
  9. Kelso
    Kelso avatar
    36 posts
    Member since:
    Dec 2013

    Posted 20 Feb 2015 in reply to Alexander Popov Link to this post

    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.
Back to Top