Hi!
I want to select root node after treeview was loaded, like this
How can I find treeview root node?
I want to select root node after treeview was loaded, like this
function
treeview_databound(e) {
var
treeview = e.sender;
var
item = treeview.dataSource.get (id_root_node); // How do I determine root node?
if
(item) {
var
node = treeview.findByUid (item.uid);
treeview.select (node);
}
}
$(
"#splitted_tree_window_left"
).
kendoTreeView({
// ...
dataBound : treeview_databound,
});
4 Answers, 1 is accepted
0
Hello Maksim,
Alex Gyoshev
Telerik
You can supply CSS selectors to the treeview select method, so selecting the first root item would be treeview.select(".k-item:first"). Also, you might want to select the node only once (since the dataBound event is fired on every binding of the treeview). Here is a jsBin sample that shows this approach.
Regards,Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0

Maksim
Top achievements
Rank 1
answered on 22 May 2013, 06:55 AM
Alex, thanks for solution.
Yes, I want to select root node just once, when tree was fully loaded.
But I can't find appropriate event.
What tree.one("dataBound", function()) actually does?
I want to display selected node info once it was selected. Actually I need something like this
Your approach works, but it does not fire kendoTreeView select event.
Are there any workarounds?
P.S. I am on kendoui 2012.3.1114 and an upgrade would be something risky
Yes, I want to select root node just once, when tree was fully loaded.
But I can't find appropriate event.
What tree.one("dataBound", function()) actually does?
I want to display selected node info once it was selected. Actually I need something like this
function treeview_databound(e) {
var treeview = e.sender;
var item = treeview.dataSource.get (id_root_node);
if (item) {
var node = treeview.findByUid (item.uid);
treeview.select (node);
treeview_onselect_node (node); // I can bind this to treeview select event and use your approach
}
}
Your approach works, but it does not fire kendoTreeView select event.
Are there any workarounds?
P.S. I am on kendoui 2012.3.1114 and an upgrade would be something risky
0
Hello Maksim,
Alex Gyoshev
Telerik
> What tree.one("dataBound", function()) actually does?
http://docs.kendoui.com/api/framework/observable#methods-one
> Your approach works, but it does not fire kendoTreeView select event.
Methods do not trigger events by design. You can trigger the event manually or call the needed event handlers after selecting the node.
Alex Gyoshev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted

Maksim
Top achievements
Rank 1
answered on 23 May 2013, 06:52 AM
I triggered my event manually
It worked. Thanks, Alex!
function treeview_databound(e) {
var treeview = e.sender;
var root = $('.k-item:first');
treeview.select(root);
treeview.trigger('select', {node: root});
}