Select event isn't triggered when programatically selected

3 posts, 0 answers
  1. Michael
    Michael avatar
    3 posts
    Member since:
    Oct 2012

    Posted 23 Oct 2012 Link to this post

    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 ( 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?
  2. Miika
    Miika avatar
    28 posts
    Member since:
    Jun 2012

    Posted 06 Nov 2012 Link to this post

    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;

    // 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.
  3. David
    David avatar
    1 posts
    Member since:
    Feb 2019

    Posted 24 Jun 2019 in reply to Miika Link to this post

    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

Back to Top