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

find root node of a TreeView

4 Answers 1172 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Maksim
Top achievements
Rank 1
Maksim asked on 21 May 2013, 01:19 PM
Hi!

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,
});
How can I find treeview root node?

4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 22 May 2013, 06:43 AM
Hello Maksim,

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
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
Alex Gyoshev
Telerik team
answered on 22 May 2013, 07:18 AM
Hello Maksim,

> 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.

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
Accepted
Maksim
Top achievements
Rank 1
answered on 23 May 2013, 06:52 AM
I triggered my event manually
function treeview_databound(e) {
 
    var treeview = e.sender;
 
    var root = $('.k-item:first');
    treeview.select(root);
    treeview.trigger('select', {node: root});
}
It worked. Thanks, Alex!
Tags
TreeView
Asked by
Maksim
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Maksim
Top achievements
Rank 1
Share this question
or