Rebuild TreeView with new data

4 posts, 0 answers
  1. Igor
    Igor avatar
    26 posts
    Member since:
    Nov 2010

    Posted 21 Dec 2011 Link to this post

    Hello,

    I want to rebuild the Treeview with new data. I use this code:
    $(#treview)
        .removeClass('k-treeview')
        .empty();
    $(#treeview).kendoTreeView({
        dataSource: getNewdata(),
        select: onNodeSelect
    });

    The tree is rebuild well but the function onNodeSelect is called two times if I select a node.
    Is there a way to  clear also event handling for select? 
  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2527 posts

    Posted 22 Dec 2011 Link to this post

    Hello Igor,

    Theoretically, using the treeview API should be cleaner:

        var kendoTree = treeview.data("kendoTreeView"); 

        // clear the treeview and unbind handlers
        kendoTree.remove(".k-item");
        kendoTree.unbind("select");
        
        // bind new data and add handler
        kendoTree.append(getData());
        kendoTree.bind("select", function() { alert("rebound select"); }); 


    However, we discovered several bugs while we were testing this approach, which have been fixed in the attached JavaScript.

    Kind regards,
    Alex Gyoshev
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Igor
    Igor avatar
    26 posts
    Member since:
    Nov 2010

    Posted 22 Dec 2011 Link to this post

    Thank you it works!
  4. Constantine
    Constantine avatar
    9 posts
    Member since:
    Apr 2012

    Posted 23 Jul 2012 Link to this post

    This has to be in Docs How-to's
Back to Top