This is a migrated thread and some comments may be shown as answers.
Adding nodes to an existing tree via client side script
3 Answers 62 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oded
Top achievements
Rank 1
Oded asked on 13 Jun 2011, 12:17 PM
Hi,

I have a an mvc treeview that is initially rendered on the page through a partial view. This is working fine.

I have a combobox on the page and now I need to add a node to the tree based on the selection in the combobox.

I would like to do this in the client side but I couldn't find the right way to do it.

Can I add a node to an already existing node through client side?

This is the partial view of the treenode:

@model Model
@(Html.Telerik().TreeView()
    .Name("TreeView")
    .Items(item => {
        item.Add()
        .Text(Model.Root.ParentName)
        .Value(Model.Root.Value)
        .HtmlAttributes(new {
            MId = Model.Root.Id,
            Type = Model.Root.Type
        }).Items(subItem => {
            for (int i = 0; i < Model.ChildNodes.Count; i++)
            {
                subItem.Add()
                    .Text(Model.ChildNodes[i].Name)
                    .Value(Model.ChildNodes[i].Value)
                    .HtmlAttributes(new {
                        MId= Model.ChildNodes[i].Id,
                        Type = Model.ChildNodes[i].Type
                    });
            }
        });
    }).ExpandAll(true)
)


This is the Action method that returns the partial view:

public ActionResult Hierarchy(int id, Type type)
        {
            var list = new List<Models.someType>();
  
            var nodes = service.GetNodes();
  
            HierarchyModel model = new HierarchyModel {
                Root = new HierarchyModel {
                    Id = nodes[0].Id,
                    Name = nodes[0].Name,
                    Type = (Models.Type)nodes[0].Type,
                    Level = nodes[0].Level,
                    Lineage = nodes[0].Lineage
                },
                ChildNodes = (from n in nodes
                              where n.Level == 2
                              select new HierarchyModel {
                                  Id = n.Id,
                                  Name = n.Name,
                                  Type = (CompanyType)n.Type,
                                  Level = n.Level,
                                  Lineage = n.Lineage
                              }).ToList()
            };  
  
  
            return PartialView("Hierarchy", model);
        }

Thanks you,

Oded Tal

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 13 Jun 2011, 03:03 PM
Hi Oded,

 This is currently not supported. We have it logged as a feature request here and you may consider casting your vote. Votes help us give priority to feature requests.

All the best,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Travis
Top achievements
Rank 1
answered on 19 Sep 2011, 09:30 PM
Would be nice to have this feature.
0
Roatin Marth
Top achievements
Rank 1
answered on 16 Feb 2012, 09:48 PM
This is now supported in the 2012 Q1 release!
Tags
TreeView
Asked by
Oded
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Travis
Top achievements
Rank 1
Roatin Marth
Top achievements
Rank 1
Share this question
or