Hi,
I have some client-side code that receives a block of information from the server. This information is then used to dynamically alter the tree client-side ... all this works well and i'm very happy with this.
I have a client event subscribed to for the ClientNodeExpanded event, which fires quite nicely when the user hits the + on the tree nodes.
However it does note appear to fire at all if I do node.expand(); in my JavaScript?
Is there any way to fire the ClientNodeExpanded event from Javascript (or should I be doing node.expand() differently?)
Thanks.
I have some client-side code that receives a block of information from the server. This information is then used to dynamically alter the tree client-side ... all this works well and i'm very happy with this.
I have a client event subscribed to for the ClientNodeExpanded event, which fires quite nicely when the user hits the + on the tree nodes.
However it does note appear to fire at all if I do node.expand(); in my JavaScript?
Is there any way to fire the ClientNodeExpanded event from Javascript (or should I be doing node.expand() differently?)
Thanks.
5 Answers, 1 is accepted
0
Hello Brian,
Welcome to Telerik Community!
Actually, we decided to be that way by design.
The reason is that when you call the expand() client-side method - you can put the code that would handle the OnClientNodeExpanding/OnClientNodeExpanded underneath/around it.
For example: let's say you want to put alert in the OnClientNodeExpanding and OnClientNodeExpanded handlers. These events will fire if the user expand a node with the mouse, but since these events do not fire when you call the expand() method you can do the following:
alert("before expand");
node.expand();
alert("after expand");
This is the same as firing the events - you can put all your logic not in the event handler, but around the expand() call.
I hope this helps.
Regards,
Veskoni
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Welcome to Telerik Community!
Actually, we decided to be that way by design.
The reason is that when you call the expand() client-side method - you can put the code that would handle the OnClientNodeExpanding/OnClientNodeExpanded underneath/around it.
For example: let's say you want to put alert in the OnClientNodeExpanding and OnClientNodeExpanded handlers. These events will fire if the user expand a node with the mouse, but since these events do not fire when you call the expand() method you can do the following:
alert("before expand");
node.expand();
alert("after expand");
This is the same as firing the events - you can put all your logic not in the event handler, but around the expand() call.
I hope this helps.
Regards,
Veskoni
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Brian
Top achievements
Rank 1
answered on 30 Jul 2008, 07:15 PM
Ok, that makes sense and I understand -- but to just make absolutely clear:
You are telling me that when node.expand() is called, the node is expanded BEFORE continuing, and as soon as the next line of Client code is executed the node is guaranteed to be expanded?
What about load on demand nodes? The nodes that i'm telling to expand, load on demand .. sometimes the loading can take a while.
The reason I ask is that it's one of the child nodes that I want to highlight; but at this point in time the child node isn't loaded client side, so i'd like to tell the parentNode to expand -- and I need to know the loading has finish (again client side) so I can highlight.
You are telling me that when node.expand() is called, the node is expanded BEFORE continuing, and as soon as the next line of Client code is executed the node is guaranteed to be expanded?
What about load on demand nodes? The nodes that i'm telling to expand, load on demand .. sometimes the loading can take a while.
The reason I ask is that it's one of the child nodes that I want to highlight; but at this point in time the child node isn't loaded client side, so i'd like to tell the parentNode to expand -- and I need to know the loading has finish (again client side) so I can highlight.
0
Hello Brian,
In this case, when the ExpandMode of the node is either ServerSideCallBack or WebService two additional client-side events fire: OnClientNodePopulating and OnClientNodePopulated.
You can subscribe to the latter to gain access to the nodes that have been added in the NodeExpand server-side event.
I hope this helps.
Sincerely yours,
Veskoni
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
In this case, when the ExpandMode of the node is either ServerSideCallBack or WebService two additional client-side events fire: OnClientNodePopulating and OnClientNodePopulated.
You can subscribe to the latter to gain access to the nodes that have been added in the NodeExpand server-side event.
I hope this helps.
Sincerely yours,
Veskoni
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Christian
Top achievements
Rank 1
answered on 20 Aug 2008, 02:05 PM
Hello,
I have an similar problem in my project.
I use ServerSideCallback to load the childnodes of my tree.
What I want is the following:
Right click my Node --> Select create New ChildNode from the contextmenu --> expand and show the childNodes --> insert an new Node with text "newNode" --> call startEdit() on this Node.
How can I achieve this?
Btw, what is the difference between node.expand() and node.set_expanded(true)?
here is some javascript code:
I have an similar problem in my project.
I use ServerSideCallback to load the childnodes of my tree.
What I want is the following:
Right click my Node --> Select create New ChildNode from the contextmenu --> expand and show the childNodes --> insert an new Node with text "newNode" --> call startEdit() on this Node.
How can I achieve this?
Btw, what is the difference between node.expand() and node.set_expanded(true)?
here is some javascript code:
function contextMenuItemClicked(sender, eventArgs) |
{ |
var node = eventArgs.get_node(); |
var item = eventArgs.get_menuItem(); |
var treeView = node.get_treeView(); |
if(item.get_value() == 'delete') |
removeNode(node); |
if(item.get_value() == 'cut') |
cutNode(node); |
if(item.get_value() == 'copy') |
copyNode(node); |
if(item.get_value() == 'paste') |
pasteNode(node); |
if(item.get_value() == 'rename') |
node.startEdit(); |
if(item.get_value() == 'new') |
{ |
lastCommand = "new"; |
node.expand(); |
} |
} |
function onNodePopulated(sender, eventArgs) |
{ |
var node = eventArgs.get_node(); |
var treeView = node.get_treeView(); |
if(lastCommand == "new") |
{ |
treeView.get_contextMenus()[0].hide(); |
var newNode = new Telerik.Web.UI.RadTreeNode(); |
newNode.set_text("neuer Ordner"); |
newNode.set_value("dummy1"); |
node.get_nodes().add(newNode); |
newNode.select(); |
//treeView.commitChanges(); |
newNode.startEdit(); |
} |
lastCommand = ""; |
} |
function onNodeEditing(sender, args) |
{ |
if(args.get_node().get_text() != args.get_newText()) |
{ |
xxx._webServices.ajaxServices.CreateNode(args.get_node().get_value(), args.get_newText(), function(result, eventArgs) |
{ |
//..... |
}, failedCallback); |
} |
} |
0
Hi Christian,
Please find attached a sample project demonstrating the approach.
I hope this helps.
Greetings,
Veskoni
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Please find attached a sample project demonstrating the approach.
I hope this helps.
Greetings,
Veskoni
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.