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

Callback when tree is ready

7 Answers 1117 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gal Bruck
Top achievements
Rank 1
Gal Bruck asked on 14 Nov 2012, 02:58 PM
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

7 Answers, 1 is accepted

Sort by
0
Accepted
Alex Gyoshev
Telerik team
answered on 14 Nov 2012, 04:10 PM
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!
0
Gal Bruck
Top achievements
Rank 1
answered on 15 Nov 2012, 08:55 AM
Thanks a lot Alex, that did the trick!
0
John
Top achievements
Rank 2
answered on 27 Nov 2012, 04:55 PM
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-
0
Rajashree
Top achievements
Rank 1
answered on 25 Dec 2015, 12:49 PM

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.

0
Eyup
Telerik team
answered on 25 Dec 2015, 02:05 PM
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!
 
0
Fernando
Top achievements
Rank 1
answered on 26 Feb 2016, 10:29 AM

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.

0
Eyup
Telerik team
answered on 02 Mar 2016, 07:02 AM
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!
 
Logesh
Top achievements
Rank 1
commented on 03 Oct 2022, 05:20 AM

Hey Eyup, 

 

In my scenario, i need to repopulate the tree date if they editing tree with already selected data, in the case i use databound means it calling data bound many times, is there any methods there for tree is loaded data or not

 

Regards

Logesh

Martin
Telerik team
commented on 05 Oct 2022, 03:05 PM

Would the loadCompleted event be helpful to you? If not, kindly provide some additional information about your scenario so that I can provide further assistance.
Tags
TreeView
Asked by
Gal Bruck
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Gal Bruck
Top achievements
Rank 1
John
Top achievements
Rank 2
Rajashree
Top achievements
Rank 1
Eyup
Telerik team
Fernando
Top achievements
Rank 1
Share this question
or