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

ComboBox in cell

5 Answers 198 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Sergi0
Top achievements
Rank 1
Sergi0 asked on 03 Feb 2015, 02:58 PM
Hi,

How can i add combobox to some cell in the Edit mode? Is there example for this?

5 Answers, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 05 Feb 2015, 10:29 AM
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.

 
0
Sergi0
Top achievements
Rank 1
answered on 20 Feb 2015, 12:53 PM
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?
0
Alexander Popov
Telerik team
answered on 24 Feb 2015, 01:17 PM
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.

 
0
Sergi0
Top achievements
Rank 1
answered on 24 Feb 2015, 02:55 PM
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"?


0
Alexander Popov
Telerik team
answered on 26 Feb 2015, 09:47 AM
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.

 
Tags
TreeList
Asked by
Sergi0
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Sergi0
Top achievements
Rank 1
Share this question
or