Here is the code I am using to create the TreeView...
01.
@(Html.Kendo().TreeView()
02.
.Name(
"CategoryTree"
)
03.
.TemplateId(
"TreeViewTemplate"
)
04.
.HtmlAttributes(
new
{ })
05.
.DataTextField(
"Description"
)
06.
.AutoScroll(
false
)
07.
.LoadOnDemand(
true
)
08.
.Events(e => e.Select(
"_CategoryChooserView_OnCategorySelected"
))
09.
.Events(e => e.Expand(
"_CategoryChooserView_OnCategoryExpand"
))
10.
.Events(e => e.Collapse(
"_CategoryChooserView_OnCategoryCollapsed"
))
11.
.Animation(
true
)
12.
//.DataSpriteCssClassField("DataSpriteCSSClass")
13.
.DataSource(d => d
14.
.Model(m => m
15.
.Id(
"CategoryCode"
)
16.
.HasChildren(
"HasChildren"
)
17.
)
18.
.Read(read => read.Action(
"ListSubCategories"
,
"Services"
))
19.
.Events(e => e.RequestEnd(
"_CategoryChooserView_OnCategoryRequestEnd"
))
20.
.Events(e => e.RequestStart(
"_CategoryChooserView_OnCategoryRequestStart"
))
21.
))
After the Treeview is instantiated, I want to call a JavaScript function like this one to expand and select a particular node. The node is not necessarily a top level node - it could be quite a ways down in the hierarchy.
01.
function
_CategoryChooserView_SelectNode(CategoryCode)
02.
{
03.
04.
if
(CategoryCode.length > 0)
05.
{
06.
var
TreeView = $(
"#CategoryTree"
).data(
"kendoTreeView"
);
07.
var
DataItem = TreeView.dataSource.get(CategoryCode);
08.
09.
if
(DataItem)
10.
{
11.
var
Node = treeview.findByUid(DataItem.uid);
12.
treeview.select(Node);
13.
14.
ScrollElementToScrollableParent(Node);
15.
}
16.
}
17.
}
The problem is that DataItem (line 7) comes back undefined every time, no matter what I feed "get()" method. It seems to me that with a client side Treeview that fetches its data from a remote source upon expansion of a node, this can never be possible.
How can I programmatically expand and work my way down to the node I want selected? I somehow need to expand each node down to the target node. Is it even possible?