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

Expand and Select Node with ID in TreeView

1 Answer 1863 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
KRichter
Top achievements
Rank 1
KRichter asked on 12 Jul 2013, 06:07 AM
Hi,

I'm almost done with the code from the subject. The tree expands already to the given ID, but unfortunately it does not select the node given by ID

Edit: Just to clarify, because I read a few threads regarding this issue - I don't get any error messages nor do I get 'undefined' for any variables. The node just doesn't get selected.

function expandAndSelectNode(id, treeViewName) {
    // get the Kendo TreeView widget by it's ID given by treeviewName
    var treeView = $(treeViewName).data('kendoTreeView');
     
    // find node with data-id = id
    var item = $(treeViewName).find("li[data-id='" + id + "']").find(".k-in");
     
    // expand all parent nodes
    $(item).parentsUntil('.k-treeview').filter('.k-item').each(
                function (index, element) {
                    $(treeViewName).data('kendoTreeView').expand($(this));
                }
            );
     
    // get DataSourceItem by given id
    var nodeDataItem = treeView.dataSource.get(id);
 
    //get node within treeview widget by uid
    var node = treeView.findByUid(nodeDataItem.uid);

    $(treeView).select(node);
    //treeView.select(".k-item:last");
}

I also tried $(treeView).select(item), since it should already point to the <span> item I want to select anyway. This didn't work.
Then I tried tried $(treeView).select(item.closest('.k-item')), since it points to the parent <li> element, but this didn't work either.
 The uncommented line (treeView.select(".k-item:last")) was just for testing and works.

I'm a little bit stuck and glad about any hints.

1 Answer, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Jul 2013, 10:29 AM
Hi,

The treeview object should not be wrapped in order to use the treeview methods and not the jQuery methods e.g.

treeView.select(node);
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
KRichter
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Share this question
or