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

Add a parent node when using BindTo

2 Answers 135 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Silver
Top achievements
Rank 1
Silver asked on 12 Sep 2012, 02:28 PM
I am binding tree view to a model. I want to add 'static' parent node. Is it possible? Here is code I am using now. 

<%
= Html.Telerik().TreeView()
           
.Name("TreeView")
           
.BindTo(Model, mappings =>
           
{
                mappings
.For<Employees>(binding => binding
                       
.ItemDataBound((item, emp) =>
                       
{
                            item
.Text = emp.EmpName;
                       
}));                    
           
})            
%>

2 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 17 Sep 2012, 08:04 AM
This functionality is not supported. You can add one item through the Items method and load its subnodes through a DataSource binding.

Regards,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Devon
Top achievements
Rank 1
answered on 27 Sep 2012, 08:00 PM
Although the tree doesn't support it you can work around it using a List inside your model.

I needed a static node called "UserList" that is in every "company" 
View:
mappings.For<OAEntity.Company>(binding => binding
         .ItemDataBound((item, company) =>
         {
             item.Text = @Html.Partial("CompanyLabel", company).ToHtmlString();
             item.Id = company.CompanyID.ToString();
             item.HasChildren = true;
         })
         .Children(company => ((company.UserLists)));
 
           mappings.For<OAEntity.UserList>(binding => binding
           .ItemDataBound((item, user) =>
           {
               item.Text = @Html.Partial("UserListLabel", user).ToHtmlString();
               item.Id = user.CompanyID.ToString();
               item.HasChildren = user.AspnetUser.Any();
           }).Children(location => location.AspnetUser));
 
           mappings.For<OAEntity.Aspnet_User>(binding => binding
           .ItemDataBound((item, user) =>
           {
               item.Text = @Html.Partial("UserLabel", user).ToHtmlString();
               item.Id = user.UserId.ToString();
               item.HasChildren = false;
           }));


Here is my model (Open Access):
    public partial class Company
    {
         public IEnumerable<UserList> UserLists
        {
            get
            {
                IEnumerable<UserList> pwa = new List<UserList>
                {
                    new UserList { Title = "Users", AspnetUser = this.Aspnet_Users, CompanyID = this._companyID }
                };
                return pwa;
            }
         }
 
 
    public class UserList
    {
        public string Title;
        public IEnumerable<Aspnet_User> AspnetUser;
        public Guid CompanyID;
        public UserList()
        {
        }
 
    }
}


This will return a UserList "model" that can be bound to the tree.
Tags
TreeView
Asked by
Silver
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Devon
Top achievements
Rank 1
Share this question
or