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

Select event isn't triggered when programatically selected

2 Answers 480 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 23 Oct 2012, 07:10 PM
I have a Kendo UI treeview with a select handler. Right now, everything works if I select a node manually, but if I use the select method (http://docs.kendoui.com/api/web/treeview#select) my handler isn't triggered. Am I doing something wrong, or is this intended?
Also, is there a way to trigger the select event handler in code after selecting the element?
Thanks

2 Answers, 1 is accepted

Sort by
0
Miika
Top achievements
Rank 1
answered on 06 Nov 2012, 08:15 AM
Had this problem too. Programmatically selecting a tree node just causes the visual changes, but then you also need to trigger the event manually using the following code:

var treeView = $("#treeElement").data("kendoTreeView");
var getitem = treeView.dataSource.get(nodeID);
var selectitem = treeView.findByUid(getitem.uid);

// Mark the node as selected
treeView.select(selectitem);

// Trigger the event on the selected node.
var treeView = $("#treeElement").data("kendoTreeView");
treeView.trigger( 'select', {node: selectitem} );


This turned out to be good behaviour for me, because there were cases where I just wanted it to show up as selected, and others where I wanted it also to be triggered.
0
David
Top achievements
Rank 1
answered on 24 Jun 2019, 03:09 PM

Just FYI....for the special case where you just want to select the first node (typical when initialing showing a page), you can use this slightly simpler code:

            // Select the first TreeView node
            $("#treeElement").data("kendoTreeView").select(".k-first");

Tags
TreeView
Asked by
Michael
Top achievements
Rank 1
Answers by
Miika
Top achievements
Rank 1
David
Top achievements
Rank 1
Share this question
or