Take the 2-minute tour ×

I'm just starting to use the Telerik asp.net mvc and I'm stuck on trying to add a node to the tree view via javascript... but I don't see anything in the documentation where this is possible. Anyone done this or maybe can point in the right direction where to find docs or examples?

Here is the code I used to setup the treeview:

@using (Html.BeginForm("Index", "Listings", FormMethod.Post, new { id = "frmListings", name = "frmListings" }))
        .ClientEvents(e => e.OnSelect("onSelect"))
        .BindTo(Model.Topics, mappings => mappings.For<Topic>(binding => binding
                                                .ItemDataBound((item, category) =>
                                                                    item.Text = category.Name;
                                                                    item.Value = category.URI + "|" + category.Id.ToString();
                                                                    item.Selected = (Model.CurrentCategory.Id == category.Id);
                                                                    //item.Expanded = item.Selected;
                                                .Children(category => category.Children)

share|improve this question
What kind of binding are you using for the TreeView? –  M.Babcock Jan 9 '12 at 0:40
I believe it's server or non-ajax version... –  bbqchickenrobot Jan 9 '12 at 2:40
add comment

1 Answer

up vote 1 down vote accepted

Currently, as of Q3 2011 SP1, there is no client-side API for adding or removing nodes from the TreeView. This has however been logged in Telerik's Public Issue Tracking System (PITS) right here. If you want to see this feature in an upcoming release voting adding a commenting on the issue helps greatly.

In the meantime, if this is just for the visual of adding nodes, you can take a look at the HTML generated by the TreeView and add your own elements by doing some HTML manipulation utilizing JavaScript. The TreeView at its core is just a <ul> element with individual <li> elements representing the nodes, so you could go ahead and add your own <li> elements. This will not be reflected in the TreeView's data however.

share|improve this answer
Figured this was going to be the case. Just thought someone may have an example. In any case- maybe I could use jquery, then once the node is added use an ajax query to repopulate the TreeView and then expand the new node added... –  bbqchickenrobot Jan 9 '12 at 19:17
That should definitely work! You can refer to this documentation article (telerik.com/help/aspnet-mvc/…) to see an example of how to expand nodes on the client-side, or you can set the expanded property of the node to true right in your View. –  carlbergenhem Jan 9 '12 at 21:12
add comment

Your Answer


