I guess these aren't really problems per se, but I'd find it odd if I were the only one that wanted to see these fixes implemented, so I have decided to create a thread with a fix in the hopes that someone will clean it up and make it a permanent solution, and that I can help others with a similar problem implement the missing functionality.
So starting with shift click...
Pay special attention to body onkey events in my provided code. This has been tested in IE and FireFox.
Known limitations:
1. When shift selecting from a child through another parent, it gets weird. As it stands now, this allows shift selecting under the parent of the beginning of the first shift click ONLY, and I don't have the need or the time to get into fixing that, although I suspect it's an easy fix. It does, however, allow for shift clicking up and down the current node.
2. You can shift click, then ctrl-click other items, but if you do a subsequent shift click, it gets weird again. Once again, I don't have the need to fix this at the moment.
My subsequent post will cover copying and pasting an entire tree node. It should be noted that this script and the following script can be used in conjunction (I am actually using both on the same page).
So starting with shift click...
<body onkeydown=
"setShift(event)"
onkeyup=
"setShift(event)"
>
<telerik:RadCodeBlock runat=
"server"
ID=
"RadCodeBlock1"
>
<script type=
"text/javascript"
>
//I normally put this code right in the form (first item)
var
shiftKey=
false
;
var
treeView;
function
pageLoad()
{
treeView = $find (
"<%= treeYourTree.ClientID %>"
);
}
//capture the shift key for copying
function
setShift(e)
{
if
(window.event)
{
shiftKey = window.event.shiftKey;
}
else
{
if
(e.shiftKey)
{
shiftKey=
true
;
}
else
{
shiftKey=
false
;
}
}
}
function
onNodeClicked(sender, eventArgs)
{
if
(shiftKey)
{
treeView.trackChanges();
//We should have selected nodes if we are shift clicking
if
(treeView.get_selectedNodes!=
null
)
{
//Capture the first selected node and the current selected node
var
firstSelected = treeView.get_selectedNodes()[0];
var
currentSelected = eventArgs.get_node();
//Unselect all the nodes and initialize the continue / iteration boolean
treeView.unselectAllNodes;
var
cont=
false
;
//Iterate through the parent's children (iterate through the same level as selected)
for
(
var
i=0; i< firstSelected.get_parent().get_nodes().get_count(); i++)
{
currItNode = firstSelected.get_parent().get_nodes().getNode(i);
cont = (cont)? !(currItNode == firstSelected || currItNode == currentSelected)
:(currItNode == firstSelected || currItNode == currentSelected);
if
(cont && firstSelected.get_parent().get_nodes().getNode(i))
firstSelected.get_parent().get_nodes().getNode(i).select();
}
}
treeView.commitChanges();
}
}
</script>
</telerik:RadCodeBlock>
<-- tree goes somewhere
in
here
with
OnClientNodeClicked=
"onNodeClicked"
-->
</body>
Known limitations:
1. When shift selecting from a child through another parent, it gets weird. As it stands now, this allows shift selecting under the parent of the beginning of the first shift click ONLY, and I don't have the need or the time to get into fixing that, although I suspect it's an easy fix. It does, however, allow for shift clicking up and down the current node.
2. You can shift click, then ctrl-click other items, but if you do a subsequent shift click, it gets weird again. Once again, I don't have the need to fix this at the moment.
My subsequent post will cover copying and pasting an entire tree node. It should be noted that this script and the following script can be used in conjunction (I am actually using both on the same page).