Hi,
I have a RadTreeView control with checkboxes enabled.I have set the checkChildNodes property to true. so when i check/uncheck on parent node all the child nodes under it gets checked/unchecked.
Now my requirement is all the child nodes should get checked only when i double click on parent node and if i just make a single click only individual nodes should get checked ? how to make it possible any ideas or sample code would be appreciated. please reply asap.
Thanks in advance.
I have a RadTreeView control with checkboxes enabled.I have set the checkChildNodes property to true. so when i check/uncheck on parent node all the child nodes under it gets checked/unchecked.
Now my requirement is all the child nodes should get checked only when i double click on parent node and if i just make a single click only individual nodes should get checked ? how to make it possible any ideas or sample code would be appreciated. please reply asap.
Thanks in advance.
15 Answers, 1 is accepted
0
Hi mn moule,
I've created a sample project to fit your scenario. You can find it in the attached .zip file.
At first I've subscribed to the OnClientNodeChecking event and cancel it so that the only way to check/uncheck a node will be by clicking once on the node's text:
Here's the code for single and double-click on a node:
Please let me know if you have more questions.
Regards,
Veronica Milcheva
the Telerik team
I've created a sample project to fit your scenario. You can find it in the attached .zip file.
At first I've subscribed to the OnClientNodeChecking event and cancel it so that the only way to check/uncheck a node will be by clicking once on the node's text:
function
nodeChecking(sender, args) {
args.set_cancel(
true
);
}
Here's the code for single and double-click on a node:
function
clientDoubleClickHandler(sender, args) {
var
currentNode = args.get_node();
var
allNodes = currentNode.get_allNodes();
if
(currentNode.get_checked()) {
for
(
var
i = 0; i < allNodes.length; i++) {
allNodes[i].set_checked(
false
);
currentNode.set_checked(
false
);
}
}
else
{
for
(
var
i = 0; i < allNodes.length; i++) {
allNodes[i].set_checked(
true
);
currentNode.set_checked(
true
);
}
}
}
function
clientNodeClickingHandler(sender, args) {
var
currentNode = args.get_node();
if
(currentNode.get_allNodes().length == 0) {
if
(currentNode.get_checked()) {
currentNode.set_checked(
false
);
}
else
{
currentNode.set_checked(
true
);
}
}
}
Please let me know if you have more questions.
Regards,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
mn moule
Top achievements
Rank 1
answered on 16 Sep 2010, 09:02 AM
One more thing all my parent nodes will load the child ondemand. so for the first time when i dblclick on the parentnode only it is checked and all its child nodes remains unchecked. but from the second time it works as expected. how to overcome this on first time.
0
Hello mn moule,
What ExpandMode do you use for the Load On Demand functionality?
I suggest you using TreeNodeExpandMode.ServerSideCallBack as it does not cause a postback:
In my example I create 100 children on expand of the root node. All is done asyncronously from the client without postback. The client-side code remains the same.
Again find the full code in the attached .zip file.
Please let me know if you have some questions.
All the best,
Veronica Milcheva
the Telerik team
What ExpandMode do you use for the Load On Demand functionality?
I suggest you using TreeNodeExpandMode.ServerSideCallBack as it does not cause a postback:
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!Page.IsPostBack)
{
RadTreeNode newNode =
new
RadTreeNode(
"Root"
);
newNode.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
RadTreeView1.Nodes.Add(newNode);
}
}
protected
void
RadTreeView1_NodeExpand(
object
sender, RadTreeNodeEventArgs e)
{
RadTreeNode node = e.Node
as
RadTreeNode;
for
(
int
i = 0; i < 100; i++)
{
node.Nodes.Add(
new
RadTreeNode(
"Child Node"
+ i));
}
}
In my example I create 100 children on expand of the root node. All is done asyncronously from the client without postback. The client-side code remains the same.
Again find the full code in the attached .zip file.
Please let me know if you have some questions.
All the best,
Veronica Milcheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
HL
Top achievements
Rank 1
answered on 12 Oct 2010, 04:11 PM
hi Veronica:
I started to use the treeview. What I want to do is to put some logic server side code to single click node event as well as the double click node event . when double click node, I want to edit node text. when I single click node, I want to add the node id as well as other information to DB. the issue is that the single click node event always fire when I double click node. how I can distinge these two events?
Thanks
Helena
I started to use the treeview. What I want to do is to put some logic server side code to single click node event as well as the double click node event . when double click node, I want to edit node text. when I single click node, I want to add the node id as well as other information to DB. the issue is that the single click node event always fire when I double click node. how I can distinge these two events?
Thanks
Helena
0
Princy
Top achievements
Rank 2
answered on 13 Oct 2010, 12:49 PM
Hello,
I belive atatching the OnClientDoubleClick event will work for you. You can invoke an ajaxRequest() to server from the client event handler and perform the required action in AjaxManager_AjaxRequest event.
Thanks,
Princy.
I belive atatching the OnClientDoubleClick event will work for you. You can invoke an ajaxRequest() to server from the client event handler and perform the required action in AjaxManager_AjaxRequest event.
Thanks,
Princy.
0
Nahid
Top achievements
Rank 1
answered on 20 Jan 2011, 02:42 PM
Hello Princy,
I need OnClientDoubleClick event to save data in DB and page will be refreash without postback. would you help me with some source code or demo project .
Thanks
Nahid
I need OnClientDoubleClick event to save data in DB and page will be refreash without postback. would you help me with some source code or demo project .
Thanks
Nahid
0
Princy
Top achievements
Rank 2
answered on 21 Jan 2011, 12:48 PM
Hello Nahid,
The following code snippet shows how to achieve this.
ASPX:
Java Script:
C#:
Thanks,
Princy.
The following code snippet shows how to achieve this.
ASPX:
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
OnAjaxRequest
=
"RadAjaxManager1_AjaxRequest"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"treeview1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"treeview1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
telerik:RadAjaxManager
>
<
telerik:RadTreeView
ID
=
"treeview1"
runat
=
"server"
OnClientDoubleClick
=
"OnClientDoubleClick"
>
<
Nodes
>
<
telerik:RadTreeNode
Text
=
"Books"
>
<
Nodes
>
<
telerik:RadTreeNode
Text
=
"Arts"
/>
<
telerik:RadTreeNode
Text
=
"Biographies"
/>
<
telerik:RadTreeNode
Text
=
"Children's Books"
/>
</
Nodes
>
</
telerik:RadTreeNode
>
</
Nodes
>
</
telerik:RadTreeView
>
Java Script:
<script type=
"text/javascript"
>
function
OnClientDoubleClick(sender, args) {
var
data = args.get_node()._getData().text;
$find(
"<%=RadAjaxManager1.ClientID%>"
).ajaxRequest(data);
}
</script>
C#:
protected
void
RadAjaxManager1_AjaxRequest(
object
sender, AjaxRequestEventArgs e)
{
string
data = e.Argument;
//store the data to db
}
Thanks,
Princy.
0
Nahid
Top achievements
Rank 1
answered on 14 Feb 2011, 12:23 PM
Hello Princy,
Thank you very much for you answer. Its very helpful...
Thanks
Nahid
Thank you very much for you answer. Its very helpful...
Thanks
Nahid
0
Gaurav
Top achievements
Rank 1
answered on 08 Mar 2011, 09:42 AM
Hi,
I have a RadTreeView control with checkboxes enabled. On click on check box, checked and unchecked functionality is going well. I want to do, if a user click on related node text (ie.
Thanks
I have a RadTreeView control with checkboxes enabled. On click on check box, checked and unchecked functionality is going well. I want to do, if a user click on related node text (ie.
telerik:RadTreeNode
), on the same time related check box must check/unchecked.Thanks
0
Princy
Top achievements
Rank 2
answered on 09 Mar 2011, 12:31 PM
Hello Gaurav,
In order to achieve this you can use the client-side OnClientNodeClicked event and use the check() method of the tree node:
ASPX:
Java Script:
Thanks,
Princy.
In order to achieve this you can use the client-side OnClientNodeClicked event and use the check() method of the tree node:
ASPX:
<
telerik:RadTreeView
runat
=
"server"
ID
=
"RadTreeView2"
CheckBoxes
=
"true"
OnClientNodeClicked
=
"ClientNodeClicked"
>
<
Nodes
>
. . . .
</
Nodes
>
</
telerik:RadTreeView
>
Java Script:
<script type=
"text/javascript"
>
function
ClientNodeClicked(sender, args) {
args.get_node().check();
}
</script>
Thanks,
Princy.
0
Andres
Top achievements
Rank 1
answered on 09 Dec 2011, 08:25 PM
Hello Princy,
I need OnClientNodeChecked event to unchek data in tree and page will be refreash without postback. would you help me with some source code or demo project.
This is the javascript code, but how should I use the UpdatePanel control or the RadAjaxManager control ?
I've tried both but neither worked.
function
onClientNodeChecked(sender, e) {
var
node = e.get_node();
if
(node.get_checked()) {
sender._postBackOnCheck =
false
;
}
setTimeout(
function
() { sender._postBackOnCheck =
true
; }, 100);
}
Thanks.
0
Hi Andres,
If you use RadAjaxManager, you can use:
You can read more about RadAjaxManager and how to use it here
All the best,
Bozhidar
the Telerik team
If you want to refresh a certain update panel you could use the following (assuming the panel's ID is UpdatePanel1):
unction onClientNodeChecked(sender, args){
__doPostBack(
'UpdatePanel1'
,
''
);
}
If you use RadAjaxManager, you can use:
$find(
"<%= RadAjaxManager.GetCurrent(Page).ClientID %>"
).ajaxRequest(
"content"
);
All the best,
Bozhidar
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Massimiliano
Top achievements
Rank 1
answered on 08 Dec 2013, 12:13 PM
I read through all the topic and need a little suggestion.
I want to disable the "selecting" of the nodes, having the checbox active, so to avoid confusion between selected/checkd.
Also I would like that upon checking a node, a couple of other controls gets updated (displaying details about the node(s) checked).
I obtained the first part with this:
And call the function in the onClientNodeClicking of the RadTreeView. It works and when you click on a node name it doesn't select it but instead checks/unchecks the box. The problem is that the server side OnNodeCheck event is only fired when you actually click on the checkbox and not when node checking it's triggered by this javascript.
Any hint on how to trigger the OnNodeCheck event even when checking/unchecking the nodes from JS?
I want to disable the "selecting" of the nodes, having the checbox active, so to avoid confusion between selected/checkd.
Also I would like that upon checking a node, a couple of other controls gets updated (displaying details about the node(s) checked).
I obtained the first part with this:
// RadTreeView disable node selection
function
TreeViewNodeClicking(sender, args) {
currentNode = args.get_node();
currentNode.set_checked(!currentNode.get_checked());
args.set_cancel(
true
);
}
And call the function in the onClientNodeClicking of the RadTreeView. It works and when you click on a node name it doesn't select it but instead checks/unchecks the box. The problem is that the server side OnNodeCheck event is only fired when you actually click on the checkbox and not when node checking it's triggered by this javascript.
Any hint on how to trigger the OnNodeCheck event even when checking/unchecking the nodes from JS?
0
Hello Massimiliano,
Try using the _checkNode function of RadTreeView. This function is used internally and will trigger both the client and server Checking events. Here's how the modified code should look like:
Regards,
Bozhidar
Telerik
Try using the _checkNode function of RadTreeView. This function is used internally and will trigger both the client and server Checking events. Here's how the modified code should look like:
function
TreeViewNodeClicking(sender, args) {
currentNode = args.get_node();
sender._checkNode(
new
Event(
"click"
), currentNode);
args.set_cancel(
true
);
}
Regards,
Bozhidar
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Massimiliano
Top achievements
Rank 1
answered on 09 Dec 2013, 03:30 PM
You are the boss Bozhidar! ;)
This works like a charm.. hope it will survive next versions since it's an "internal" function :)
This works like a charm.. hope it will survive next versions since it's an "internal" function :)