Add a parent node when using BindTo

3 posts, 0 answers
  1. Silver
    Silver avatar
    25 posts
    Member since:
    Feb 2012

    Posted 12 Sep 2012 Link to this post

    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. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2527 posts

    Posted 17 Sep 2012 Link to this post

    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!
  3. Devon
    Devon avatar
    11 posts
    Member since:
    Jul 2012

    Posted 27 Sep 2012 Link to this post

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