PDA

View Full Version : TreePanel : Merge AppendChild and Nodes.Add API's



reverseblade
Mar 17, 2011, 1:08 PM
Hello

The current behavior for tree panel is when you first time constructing you can create sub nodes with

someNode.Nodes.Add(subNode);

however after the tree is constructed and emitted to the page in the next postback you can no longer update the tree.
Instead you need to use treePanel.AppendChild(someNode.nodeId, subNode); These two api's doing the same thing and should be merged.

I believe Nodes.Add should silently call AppendChild instead

P.S I am strictly speaking modifying the tree from code behind. I am aware there are javascript integrated solutions which I do not want to use in my case.

Vladimir
Mar 17, 2011, 1:19 PM
Hi,

How we can determine that you add new node instead rebuild tree collection on the server side?
For example, you can define nodes in the markup. In this case, 'someNode.Nodes.Add(subNode)' will be executed automatically by ASP.NET during page recreating. If we add 'AppendChild' calling to Nodes.Add then on each request the nodes will be duplicated on client side

reverseblade
Mar 17, 2011, 1:46 PM
Maybe should avoid associating the children nodes with the Node collection directly but rather one should use another collection.
The current situation is annoying that, you create the tree with Nodes collection but can only update with AppendChild. Modifiying the collection doesn't do anything when you want to update tree. This is not nice API IMHO.

Vladimir
Mar 17, 2011, 1:51 PM
Hi,



Maybe should avoid associating the children nodes with the Node collection directly but rather one should use another collection.

I did not understand your idea. Can you provide more details?

reverseblade
Mar 17, 2011, 2:08 PM
To sum up , I want a clean solution with a single API to create and update my tree. You said calling AppendChild from Nodes.Add will cause duplication since it could be used from markup. I am not sure how this works.

1-) Why modifiying the Node tree doesn't update the treepanel (after another postback) ?

2-) The only solution to update the nodes is to create the trees with Nodes.API and update them with AppendChild this makes your creating and refreshing tree panel duplicate.

Vladimir
Mar 17, 2011, 2:33 PM
Hi,



1-) Why modifiying the Node tree doesn't update the treepanel (after another postback) ?

Postback or ajax request? During ajax request we returns generated script only. Tracking changes for Nodes collection is difficult (we can track add/removing (again, generate script on each add/delete of a node is not always desired because a developer can just rebuild nodes collection on server side (nodes are not saved to viewstate)) but tracking node properties changing can be difficult)
Therefore we require to perform all operations (which must be mirrored to the client side) explicitly (via methods)

reverseblade
Mar 17, 2011, 2:48 PM
I meant another DirectEvent (with postback).

I totally understand why you don't keep track nodes in viewstate. However , you should allow the user to destroy the old tree and recreate it from scratch (during a directevent) with Nodes collection. Currently this is not supported. Once a tree is created you cannot destroy and recreate purely from server-side. You can only update it with appendchild .

Vladimir
Mar 17, 2011, 3:01 PM
Hi,



However , you should allow the user to destroy the old tree and recreate it from scratch (during a directevent) with Nodes collection. Currently this is not supported. Once a tree is created you cannot destroy and recreate purely from server-side. You can only update it with appendchild


All operations are allowed from server side (append, insert, removed, collapse, expand,changing). Please see TreePanel class (TreePanel has many methods, not only AppendChild)