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

[Solved] Accessing On load demand nodes w/checkbox events.

1 Answer 144 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andrew Short
Top achievements
Rank 1
Andrew Short asked on 28 Mar 2008, 07:25 PM
I have a treeview in which I check the children on the client side when a parent node is checked.  This works great when the node is already being populated.  However, due to the size of the tree, I need to use load on demand now.  The code that I use in my OnClientNodeChecked event is:

var node = eventArgs.get_node()
var checked = node.get_checked()
var nodes = node.get_nodes()

for (var i = 0; i < nodes.get_count(); i++) {

nodes.getNode(i).set_checked(checked)

if (nodes.getNode(i).get_nodes().get_count > 0) {

UpdateAllChildren_Prometheus(nodes.getNode(i).get_nodes())

}

}
 
What I tried is adding an OnClientNodeChecking event to populate the node when it is checked by doing:

var node = eventArgs.get_node()

if (node.get_level() == 0 && node.get_nodes().get_count() == 0) {

node.expand()

}

This populates the node, but the new children are not checked after both events are fired.  It seems this may be a race condition, but am not sure.  If I then uncheck and check the parent node, this works fine as the child nodes are already present.  How can I make sure the node is populated before the OnClientNodeChecked event is fired?  Keep in mind that the user is not going to expand the node before checking it.  Hopefully I'm missing something easy. 
Thanks.

1 Answer, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 31 Mar 2008, 01:43 PM
Hi Andrew Short,

I suggest to do the following:
  • Expand the node on the OnClientNodeChecking event handler:
function onClientNodeChecking(sender, eventArgs) 
    var node = eventArgs.get_node(); 
    if (node.get_expanded() == false
    { 
        node.expand(); 
    }     

  • Call the updateAllChildren() function with setTimeout javascript function in the OnClientNodeChecked event handler:
function onClientNodeChecked(sender, eventArgs) 
    var node = eventArgs.get_node();        
    setTimeout(function() {updateAllChildren(node, node.get_checked())}, 50); 
 
function updateAllChildren(node, checked) 
    var nodes = node.get_nodes(); 
    for (var i = 0; i < nodes.get_count(); i++) 
    { 
        if (checked) 
            nodes.getNode(i).check(); 
        else 
            nodes.getNode(i).uncheck(); 
    } 


I hope this helps.
Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Andrew Short
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Share this question
or