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

3 posts, 0 answers
  1. Gabriel
    Gabriel avatar
    2 posts
    Member since:
    Nov 2015

    Posted 25 May Link to this post

    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. Dimiter Topalov
    Admin
    Dimiter Topalov avatar
    356 posts

    Posted 29 May Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Gabriel
    Gabriel avatar
    2 posts
    Member since:
    Nov 2015

    Posted 26 Jul in reply to Dimiter Topalov Link to this post

    Thank you Dimiter.
Back to Top