ComboBox in cell

6 posts, 0 answers
  1. Sergi0
    Sergi0 avatar
    6 posts
    Member since:
    Jan 2015

    Posted 03 Feb 2015 Link to this post

    Hi,

    How can i add combobox to some cell in the Edit mode? Is there example for this?
  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 05 Feb 2015 Link to this post

    Hi Sergi0,

    This can be achieved using a custom editor template. I would recommend checking this demo as well as our offline demos, which are located in the Kendo UI installation path, under the \wrappers\aspnetmvc\Examples directory. 

    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. UI for ASP.NET MVC is VS 2017 Ready
  4. Sergi0
    Sergi0 avatar
    6 posts
    Member since:
    Jan 2015

    Posted 20 Feb 2015 Link to this post

    Hi,
    I have some problem with adding child item when using DropDownList in editor template.
    When i add new item (level 0) to TreeList via toolbar all is OK.
    When i try to addChild (level 1) - click on column button and i got chrome console error:
    Uncaught ReferenceError: Company is not defined
     
    Error in Code:
     
    (function(data
    /**/) {
    var o,e=kendo.htmlEncode;with(data){o=''+e(Company.CompanyName)+'';}return o;
    })

    Events before error and after click on Add child button:
    TreeList data binding
    TreeList data bound
    TreeList data binding
    TreeList data bound
    TreeList data binding


    My View:
    @model LaborTreeViewModel
    @{
        ViewBag.Title = "Test";
        Layout = "~/Views/Shared/_contLayout.cshtml";
    }
     
    <h2>Test</h2>
    @using Cont.Web.Models.Forms
    @using Kendo.Mvc.UI
     
    <div class="demo-section k-header">
        @(Html.Kendo().TreeList<LaborTreeViewModel>()
            .Name("treelist")
                    .Toolbar(toolbar => toolbar.Create().Text("Create"))
            .Selectable(true)
            .Columns(columns =>
            {
                columns.Add().Field(e => e.WBS);
                columns.Add().Field(e => e.Name).Width(220).Title("Наименование");
                 
                columns.Add().Field(e => e.PlanDateStart).Format("{0:MMMM d, yyyy}");
                columns.Add().Field(e => e.PlanDateEnd).Format("{0:MMMM d, yyyy}");
                columns.Add().Field(e => e.Company).Template("#:Company.CompanyName#");
                columns.Add().Field(e => e.Responsible).Template("#:Responsible.ResponsibleName#");
                 
     
     
                columns.Add().Width(200).Command(c =>
                {
                    c.Edit();
                    c.CreateChild();
                })
                .HtmlAttributes(new
                {
                    style = "text-align: center;"
                });
            })
                .Editable()
                .Filterable()
            .DataSource(dataSource => dataSource
                        .Create(create => create.Action("Create", "EmployeeDirectory"))
                        .Read(read => read.Action("All", "EmployeeDirectory"))
                        .Update(update => update.Action("Update", "EmployeeDirectory"))
                        .Destroy(delete => delete.Action("Destroy", "EmployeeDirectory"))
     
                        .Model(m =>
                        {
                            m.Id(f => f.Id);
                            m.ParentId(f => f.ParentLaborId);
                            m.Field(f => f.Name).DefaultValue("Новая работа");
                            m.Field(f => f.PlanDateEnd);
                            m.Field(f => f.PlanDateStart);
                            m.Field(p => p.Company).DefaultValue(ViewData["defaultCompany"] as CompanyViewModel);
                            m.Field(p => p.Responsible).DefaultValue(ViewData["defaultResponsible"] as ResponsibleViewModel);
                        })
                        .ServerOperation(false)
     
            )
     
     
            .Events(events =>
            {
                events.Edit("onEdit");
                events.Save("onSave");
                events.Remove("onRemove");
                events.DataBinding("onDataBinding");
                events.DataBound("onDataBound");
                events.FilterMenuInit("onFilterMenuInit");
                events.Change("onChangeRow");
            })
     
            .Height(540)
     
        )
    </div>
    <script>
        var debugging = false;
        function onEdit(arg) {
            var model = arg.model;
     
            console.log("TreeList edit: " + model.FirstName + " " + model.LastName);
        }
     
        function onSave(arg) {
            //debugger;
            console.log("TreeList save");
        }
     
        function onRemove(arg) {
            console.log("TreeList remove");
        }
     
        function onDataBound(arg) {
            console.log("TreeList data bound");
        }
     
        function onDataBinding(arg) {
     
            console.log("TreeList data binding");
        }
        function onFilterMenuInit(arg) {
            console.log("TreeList onFilterMenuInit");
        }
        function onChangeRow(arg) {
            console.log("TreeList onChangeRow");
        }
         
    </script>

    If i commented fields Company and Responsible child then adding is OK.

    Why did it happen?
  5. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 24 Feb 2015 Link to this post

    Hi Sergi0,

    It looks like the complex objects Company and Responsible do not exist in the child items. I would suggest verifying if that is indeed the case and if necessary - use a null check in the template. For example: 
    #=data.NoSuchField ? data.NoSuchField : ''#"

    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.

     
  6. Sergi0
    Sergi0 avatar
    6 posts
    Member since:
    Jan 2015

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

    Hi Alexander,
    I replaced my templates to:

    columns.Add().Field(e => e.Company).Template("#=typeof(Company)!='undefined' ? Company.CompanyName:''#");
    columns.Add().Field(e => e.Responsible).Template("#=typeof(Responsible)!='undefined' ?Responsible.ResponsibleName:''#");

    And this works)
    Why older version template works with "new item" and does not work with "add child item"?


  7. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 26 Feb 2015 Link to this post

    Hello Sergi0,

    I investigated further and seems that this is caused by an incorrect behavior in the creation of child items. Basically, all children should inherit the defaultValues specified in the TreeList's DataSource, however that is not the case at this point, so I have logged an issue in our internal bug tracking system.

    As a small sign of our appreciation for bringing this to our attention I have updated your Telerik points.

    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.

     
Back to Top
UI for ASP.NET MVC is VS 2017 Ready