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

[Solved] Programmatically Select Node in MVC

4 Answers 172 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eric
Top achievements
Rank 1
Eric asked on 19 May 2011, 11:03 AM
I'm using Ajax to refresh the treeview. I'd like to select the node that was selected before the refresh.
After the tree is loaded i can't seem to select the tree with $find("TreeView"). I even tried it with a timeout, to no avail.

So I'd like to do it server side instead. I'm using a model and putting that in the tree.


<%
        Html.Telerik().TreeView()
            .Name("TreeView")
            .ExpandAll(true)
            .Items(item => Model.TreeItems(item, Model.IsAdministrator))
            .ClientEvents(events => events.OnSelect("TreeOnSelect"))
              // Like to do something like: .SelectItem(item == Model.MySelectedNode)
            .Render();
%>

4 Answers, 1 is accepted

Sort by
0
Dimo
Telerik team
answered on 19 May 2011, 01:06 PM
Hello Eric,

$find() is used in ASP.NET AJAX. You should obtain a reference to the MVC TreeView like this:

var treeview = $("#TreeViewClientID").data("tTreeView")

http://www.telerik.com/help/aspnet-mvc/telerik-ui-components-treeview-client-api-and-events.html#GetClientSideObject

All the best,
Dimo
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
Eric
Top achievements
Rank 1
answered on 19 May 2011, 02:37 PM
Ok, if I'm going the javascript way in selecting the node, then you code works well for selecting the tree (thanks).

However, I still need to select the node that was selected before the refresh, but the treeview object I'm getting back doesn't expose a findNodeByValue function.
0
Accepted
Dimo
Telerik team
answered on 19 May 2011, 04:30 PM
Hi Eric,

The TreeView selection is purely visual - a predefined "selected" style is applied to a given DOM element. As a result, if you want to persists the selection across page reloads or AJAX requests, you need to implement your own way to do that. For example, save the node text in a variable and then look for it. You can use the jQuery text() or html() methods.

Best wishes,
Dimo
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
Eric
Top achievements
Rank 1
answered on 20 May 2011, 08:19 AM
Thank you Dimo!
Tags
TreeView
Asked by
Eric
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Eric
Top achievements
Rank 1
Share this question
or