Callback when tree is ready

8 posts, 1 answers
  1. Gal Bruck
    Gal Bruck avatar
    6 posts
    Member since:
    Jun 2010

    Posted 14 Nov 2012 Link to this post

    Hello,

    I noticed there is no event that fires when the treeview is loaded. 
    How can I set the selected node of tree if there's no callback that lets me know when it's done loading?
    BTW I am using an ajax call to load the datasource.

    Is there a workaround for this? 

    Thanks
  2. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 14 Nov 2012 Link to this post

    Hello Liron,

    The dataBound event is triggered after the treeview datasource has been processed. You can use it to achieve the desired effect. Please keep in mind that the event will be triggered after each binding, so you might want to add a check if there is a selected node already.

    All the best,
    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. Kendo UI is VS 2017 Ready
  4. Gal Bruck
    Gal Bruck avatar
    6 posts
    Member since:
    Jun 2010

    Posted 15 Nov 2012 Link to this post

    Thanks a lot Alex, that did the trick!
  5. John
    John avatar
    13 posts
    Member since:
    May 2012

    Posted 27 Nov 2012 Link to this post

    I am doing the following and the alert is never getting fired...

    $("#treeview").kendoTreeView({
                        dataSource: folderTree,
                        dataTextField: "Name",
                        dataBound: function(){ alert('here'); }
                    })

    I am using a HierarchicalDataSource for the folderTree.  Am I missing something?

    -john-
  6. Rajashree
    Rajashree avatar
    2 posts
    Member since:
    Nov 2013

    Posted 25 Dec 2015 Link to this post

    Hi,

     

    The databound method gets called before data is processed. 

    Code:

     

     TreeViewBuilder treeViewCntrl = HtmlHelperExtension.Kendo(page.Html).TreeView();
                treeViewCntrl 
                    .DataTextField("Name")
                    .Checkboxes(c => c.Enabled(true).CheckChildren(true).Template("<input type='checkbox' name='checkedNode' value='#= item.Id #' />"))                
                    .DataSource(dataSource => dataSource
                        .Read(read => read
                            .Action("Action", "Controller").Data("additionalData")))
                            .Events(e => e.Expand("expand"))

                            .ExpandAll(true)

                            .Events(e => e.DataBound("DisableCheckboxes('" + mdl.SelectedFunctionIdForGrpReport + "')"));

     

    <script type="text/javascript">              
                  var additional = {};
      
                function expand(e) {
                    var id = this.dataItem(e.node).Id;
                    var name = this.dataItem(e.node).Name;
                    additional.Id = id;
                    //additional.Name = age;
                }
      
                function additionalData() {
                    return additional;        
                }  

                function DisableCheckboxes(selectedIds) {      
                        if(selectedIds != '')
                        {
                            var treeview = $('#treeViewCntrl ').kendoTreeView().data('kendoTreeView');                   
                            var ids=selectedIds.split(',');
                            alert(selectedIds);
                            /*$.each(ids, function(i, id) {{
                   var data = treeView.dataSource.getByUid(id);
                                    if (data == id) {
                                        data.set('checked', true);
                                    }
                  }});*/
                        }
                    }
                </script>

     

     

    I want to select the checkboxes by default based for the selectedIds. And disable the control.

    Please help.

     

    Thanks,

    Rajashree.

  7. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 25 Dec 2015 Link to this post

    Hello Rajashree,

    I suggest that we continue our conversation on your ticket with ID: 997808.

    Regards,
    Eyup
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  8. Juan Jose
    Juan Jose avatar
    45 posts
    Member since:
    Jul 2013

    Posted 26 Feb in reply to Eyup Link to this post

    Hello, 

    I'm interested in a solution to this aswell. I need to perform certain operations in the treeview after it has completed loading the nodes (expand certain nodes).

    How can I achieve that?

    Thanks.

  9. Eyup
    Admin
    Eyup avatar
    3014 posts

    Posted 02 Mar Link to this post

    Hi Juan,

    You can check the dataBound event handler to achieve this requirement. Please note that you should write it with a capital B:
    http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#events-dataBound

    Here is the sample to demonstrate this suggestion and some changes:
    http://dojo.telerik.com/Evuwu/25


    I hope this will prove helpful.

    Regards,
    Eyup
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready