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

TreeView not displaying children nodes when hierarchical datasource is modified

3 Answers 667 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Klaus
Top achievements
Rank 1
Klaus asked on 15 Dec 2012, 03:34 PM
The datasource for my treeview is defined as follows:

 legends = new kendo.data.HierarchicalDataSource({                   
                 schema: {
                     model: { id : "id", hasChildren: true,  children: "layers"    }
                 }
             });      

and my treeview is initialized like this:

  $("#treeview").kendoTreeView({ 
                 checkboxes : { checkChildren : true },
                 dataSource: legends }); 

This is supposed to be a dynamic data source allowing me to add and remove items during runtime.  When I add and remove items from legends, I expect the treeview to add and remove nodes accordingly.  So when I later create a model like this:

var category = {id : 0, text : "some text", expanded : true, spriteCssClass : "folder", layers : [] }

and add it to the datasource using the add method

                legends.add(category); 

I should expect to see a tree node automatically created.  This works.

If I later grab the category created above from legends.data() and add a child layer like this:

category.layers.push({ id : 1, text : " child",  someOtherData : {} });

I do not see the child appear on the treeview and my application starts behaving abnormally.   Then it occurred to me that the layers collection was not an observable and tried creating my categories like this:

var category = {id : 0, text : "some text", expanded : true, spriteCssClass : "folder", layers : new kendo.data.ObservableArray([]) }

With this change, I still get no children displayed and applpication appears to hang on call to category.layers.push().

What am I missing?

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 Dec 2012, 05:00 PM
Hi Klaus,

The correct way to append dynamically nodes to the TreeView is through the widget's API methods - append, insertAfter and insertBefore. You can test the functionality here.
To avoid potential problems please do not try to modify the Hierarchical DataSource directly but use the corresponding methods.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Volodymyr Oliinyk
Top achievements
Rank 1
answered on 04 Feb 2013, 10:08 AM
Hello,

But what to do when dataSource can be changes from other modules in the application and treeview should reflect (show) these changes?

In the normal application there is a datasource layer and presentation layer. When datasource layer is updated (by any part of the system) all presentation layers connected to this datasource should reflect these changes. As I can see ListView works in this case (it is updated when data source is updated) so why treeview doesn't?

is there any way to bind treeview to hierarchicalDataSource in the way to be updated after datasource has been changed?

Vladimir
0
Volodymyr Oliinyk
Top achievements
Rank 1
answered on 04 Feb 2013, 10:20 AM
Calling "dataSource.fetch();" solving the problem (for reflecting new items).
Tags
TreeView
Asked by
Klaus
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Volodymyr Oliinyk
Top achievements
Rank 1
Share this question
or