I'm adding new node on client side. When users presses Escape key, I have to delete new node. How do I do that? NodeEdited event wont fire in this case.
3 years ago you promised here to implement this event but nothing has changed.
Thank you.
9 Answers, 1 is accepted
You can try this javascript code that deletes the selected node after pressing the Escape key at my side:
function
OnClientKeyPressing(sender, args) {
var
treeView = $find(
"<%= RadTreeView1.ClientID %>"
);
var
node = args.get_node();
var
key = args.get_domEvent().keyCode;
if
(key ==
"27"
) {
treeView.trackChanges();
var
parent = node.get_parent();
parent.get_nodes().remove(node);
treeView.commitChanges();
}
}
Hope this is helpful.
Best wishes,
Plamen Zdravkov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Thank you for reply but OnClientKeyPressing event won't ever fire. I attached it to TreeView. Should I attach it to different control?
Here is the sample project that worked at my side. OnClientKeyPressing fires when you press a custom key and a node is selected before that.
Hope this will help.
Best wishes,
Plamen Zdravkov
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
I reproduced the issue and transferred it to our developers for further research.Thank you very much for reminding it to us.
All the best,
Plamen Zdravkov
the Telerik team
Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>
Thanks,
Chris
Thank you for sharing your interest about this case. I increased the priority of the issue. We will inform you once the issue is fixed.
Plamen Zdravkov
the Telerik team
The keydown event can be used to properly capture the pressing of the ESC key and remove a newly added node. Note that I'm using some JQuery syntax here to register the event, but you could rewrite this without JQuery. Also note that you may need to tweak this code if you want it to behave differently for aborting an edit of an existing node as opposed to aborting an edit of a new node.
var nodeInEditMode;
function onClientNodeEditStartHandler(sender, eventArgs)
{
// get the node
nodeInEditMode = eventArgs.get_node();
// get a reference to the INPUT area of the edited node
var textInput = nodeInEditMode.get_inputElement();
// set the width and id property of the INPUT
textInput.size = 15;
textInput.id = "newNodeTextInput";
// Add onclick event to text input box to handle ESC key (uses some JQuery)
$('#' + textInput.id).keydown(function (event) {
if (event.keyCode == '27') {
tree.trackChanges();
nodeInEditMode.get_parent().get_nodes().remove(nodeInEditMode);
tree.commitChanges();
}
});
}
Thank you very much for sharing your workaround of this issue with the community.
Plamen Zdravkov
the Telerik team