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

TreeView append with nested data, children dataSources do not grow to get new ids

1 Answer 373 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 21 Feb 2013, 10:23 PM
A treeview TV uses a remote hierarchical data source.

A button click on the page launches some ajax whose done() handles an array of node data that is returned.
nodes =
[ { id:101, text: "One", hasChildren: true }
, { id:201, text: "Two", hasChildren: true }
, { id:301, text: "Three", hasChildren: false }
]
The nodes are nested as follows
for (var i=1;i<nodes.length;i++) {
   nodes[i-1].items = [ nodes[i] ];
}
and appended to a treeview
TV.append ( nodes[0] );
The treeview appends them correctly as
One
 +- Two
     +- Three
However, the problem is that the children dataSources for nodes One and Two do not get updated.  The top level dataSource of TV does have get updated.  I stepped through get() using developer tools and saw that the method was properly descending into the children dataSources to locate the target value... it just wasn't there :(
uid101 = TV.dataSource.get(101); // some uid
uid201 = TV.dataSource.get(201); // undefined
uid301 = TV.dataSource.get(301); // undefined
I have also tried doing a series of appends (using the original unnested data) and had a similar to worse problem (the TV nodes don't even get placed at the correct levels).
parent = null;
parent = TV.append ( nodes[0], parent );
parent = TV.append ( nodes[1], parent );
parent = TV.append ( nodes[2], parent );

Can you suggest a technique that works for adding a new 'path' of nested nodes to TV from with my done() handler ?

1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 26 Feb 2013, 09:01 AM
Hello Richard,

If I understand the problem correctly you are unable to get the dataItem for a node which is added dynamically - if the node is not expanded (which means it is not loaded from the server at all) then it is expected have problems retrieving the dataItem.

However if the nodes are loaded and you use the get method you should retrieve the dataItem. To demonstrate this I created a jsbin which you can find here:

 http://jsbin.com/eqakuf/4/edit


Kind Regards,
Petur Subev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Richard
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or