Hi Guys,
I'm struggling a bit here with the WebTree. I'm trying to get it to expand and check all nodes when a node is checked. (Expanding of children nodes isn't too important, but would be nice).
I've seen the thread "WebTree Check All Child Nodes With Demand Load" (https://ko.infragistics.com/community/forums/f/retired-products-and-controls/16495/webtree-check-all-child-nodes-with-demand-load), but didn't find an answer there.
I've set up a clentside NodeChecked event, Tree_NodeChecked, which goes roughly like this...
function Tree_NodeChecked(treeId, nodeId, bCheck){ node = igtree_getNodeById(nodeId); nodeGuid = node.getDataKey(); if( bCheck == true ) { // Do my stuff Load_Model( nodeGuid ); // Expand the node node.setExpanded(true); // recursively tick/check child nodes var ChildNodes = node.getChildNodes(); if( node == null || ChildNodes.length == 0 ) { // Node has no children, do nothing. } else { for( ii = 0 ; ii < ChildNodes.length ; ii++ ) { ChildNodes[ii].setChecked( true ); Tree_NodeChecked( treeId, ChildNodes[ii].Id, true); } } } Else { // Do my stuff Delete_Model( nodeGuid ); }
However, it only seems to work with childnodes that have been pre-loaded in (those that I expand, then un-expand).
Anybody have any advice?
A bit of extra info:-
Nodes that have children, but have not yet been expanded by the user... in the above code, immediately after node.setExpanded(true), the node.getChildNodes( ) is empty :(.
This is expected behavior when using ManualSmartCallbacks (or AutomaticSmartCallbacks). The child nodes don't exist on the client until after the AJAX callback has finished, which takes time. Most likely, by the time you're trying to check the nodes, the AJAX callback hasn't yet finished, and so the child nodes don't exist yet.
I don't see any straightforward way to get this behavior when using smart callbacks. You might consider using Manual load-on-demand instead, and using either WARP or UpdatePanel to provide AJAX to the implementation.
I wasn't too keen on the UpdatePanel or WARP methods. I've come up with the idea of doing as below.
You'll probably all think I'm on drugs for it, but hey, maybe it'll work :).
The diagram is split between client-side methods and server-side. The entry point, "Tree_NodeChecked" is the ClientSideEvent of the WebTree.
In theory, when checking a node with multiple levels of children (with ManualSmartCallbacks), this will insert the first level of children, then allow javascript to "see" them to get their ID's, thus carrying out any client-side processes (marked red). For each newly inserted child, the process re-starts.
Hopefully, this'll look rather sweet, and have nodes appearing as they progress if the branch turns out to be quite deep. I'll report on success or failures as it happens (my time is often pulled away onto other things so this could take a few days).
Does anybody see an easier way to do this? Or see any flaws?
Random update:
That last method worked :)