R
Rich Chung
Hey folks,
I'm having an issue with checkboxes in treenodes. Basically, I'm building
nodes dynamically based on a dataset and I want to allow a user to filter a
datagrid based on items that are checked off in the tree. Requirements are
that subnodes must also be selected when a parent node's checkbox is checked
off and unselected when the parent is unselected. I'm using the following
JavaScript to perform this (in order to avoid having to postback on every
check):
<script>
function doSelect(cntrl)
{
var nodeIndex = cntrl.clickedNodeIndex;
var node = cntrl.getTreeNode(nodeIndex);
var nChk = node.getAttribute("Checked");
var nName = node.getAttribute("Text");
if (nodeIndex != null)
{
if (nChk == true)
{
alert("This item is going from unchecked to checked");
checkSubtree(cntrl, node, nodeIndex, cntrl, true);
}
else
{
alert("This item is going from checked to unchecked");
checkSubtree(cntrl, node, nodeIndex, cntrl, false);
}
}
}
function checkSubtree(tree, node, nodeIndex, tree, nChkInFunction)
{
tree.queueEvent('oncheck', nodeIndex)
node.setAttribute("checked", nChkInFunction, 0);
var children = node.getChildren();
for (var i in children)
{
var childIndex = nodeIndex + "." + i;
var child = tree.getTreeNode(childIndex);
checkSubtree(tree, child, childIndex, tree, nChkInFunction);
}
}
That seems to work ok on the client side. The user clicks a submit button
and the treeview items that are checked are recognized.
The problem is that once the page is displayed again, the checkboxes are
shown in the appropriate states, but clicking on an item that has a checkmark
next to it gives the user the "This item is going from unchecked to checked"
message and the node is no longer recognized as being checked on another post
back.
Any help would be appreciated.
Thanks!
I'm having an issue with checkboxes in treenodes. Basically, I'm building
nodes dynamically based on a dataset and I want to allow a user to filter a
datagrid based on items that are checked off in the tree. Requirements are
that subnodes must also be selected when a parent node's checkbox is checked
off and unselected when the parent is unselected. I'm using the following
JavaScript to perform this (in order to avoid having to postback on every
check):
<script>
function doSelect(cntrl)
{
var nodeIndex = cntrl.clickedNodeIndex;
var node = cntrl.getTreeNode(nodeIndex);
var nChk = node.getAttribute("Checked");
var nName = node.getAttribute("Text");
if (nodeIndex != null)
{
if (nChk == true)
{
alert("This item is going from unchecked to checked");
checkSubtree(cntrl, node, nodeIndex, cntrl, true);
}
else
{
alert("This item is going from checked to unchecked");
checkSubtree(cntrl, node, nodeIndex, cntrl, false);
}
}
}
function checkSubtree(tree, node, nodeIndex, tree, nChkInFunction)
{
tree.queueEvent('oncheck', nodeIndex)
node.setAttribute("checked", nChkInFunction, 0);
var children = node.getChildren();
for (var i in children)
{
var childIndex = nodeIndex + "." + i;
var child = tree.getTreeNode(childIndex);
checkSubtree(tree, child, childIndex, tree, nChkInFunction);
}
}
That seems to work ok on the client side. The user clicks a submit button
and the treeview items that are checked are recognized.
The problem is that once the page is displayed again, the checkboxes are
shown in the appropriate states, but clicking on an item that has a checkmark
next to it gives the user the "This item is going from unchecked to checked"
message and the node is no longer recognized as being checked on another post
back.
Any help would be appreciated.
Thanks!