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

Rebuild TreeView with new data

3 Answers 258 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Igor
Top achievements
Rank 1
Igor asked on 21 Dec 2011, 05:51 PM
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? 

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 22 Dec 2011, 03:55 PM
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!
0
Igor
Top achievements
Rank 1
answered on 22 Dec 2011, 04:56 PM
Thank you it works!
0
Constantine
Top achievements
Rank 1
answered on 24 Jul 2012, 02:39 AM
This has to be in Docs How-to's
Tags
TreeView
Asked by
Igor
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Igor
Top achievements
Rank 1
Constantine
Top achievements
Rank 1
Share this question
or