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

angularjs treeview how to expand all nodes after tree has loaded?

2 Answers 415 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gabriel
Top achievements
Rank 1
Gabriel asked on 25 May 2016, 07:02 PM

Hello,

I have an angularjs treeview loaded from pre-set data. I need to expand the complete tree once it has finished loaded. For that I put in my controller a function 

OnDatabound  which gets executed just after the tree has been loaded; I am trying to get a reference to the treeview as shown below but I get an error:

 

in Html ...

 <div kendo-tree-view="treeview" k-options="treeOptions" 

 

in controller ....

        $scope.OnDatabound = function(args){

                         var treeview = args.sender;

                        treeview.data("kendoTreeView").expand('.k-item');  /* expand all nodes */         <<<<<<    error:     TypeError : treeview.data is not a function
           };

     $scope.treeOptions = {

                   dataTextField: "Name",
                   dataSource : $scope.FormatAndLoadMyData(theData, "Id", "parentId", 0) ,
                   dataBound: $scope.OnDatabound
    };

How do I get a reference to the treeview ? .. or .. how can I expand all nodes?

 

Thanks.

 

2 Answers, 1 is accepted

Sort by
0
Dimiter Topalov
Telerik team
answered on 30 May 2016, 07:51 AM
Hello Gabriel,

In an event handler, you can get a reference to the Kendo UI TreeView via e.sender, and then use the expandPath() method of the widget e.g.:

$scope.onDataBound = function(e){
e.sender.expandPath([1, 2, 3])
}

There are two alternative approaches to get a reference to the widget, using AngularJS, as explained here:

http://docs.telerik.com/kendo-ui/AngularJS/introduction#widget-references

Please note that when a data bound widget is referenced using this approach, the widget reference is available when wrapped in a setTimeout().

I have prepared a simple dojo, demonstrating the suggested techniques:

http://dojo.telerik.com/UqOxa/2

I hope this helps.

Regards,
Dimiter Topalov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gabriel
Top achievements
Rank 1
answered on 26 Jul 2016, 11:52 AM
Thank you Dimiter.
Tags
TreeView
Asked by
Gabriel
Top achievements
Rank 1
Answers by
Dimiter Topalov
Telerik team
Gabriel
Top achievements
Rank 1
Share this question
or