Hi,
I need to loop through the WebDataTree in JavaScript and get a list of all "selected" checkboxes. I tried the below code. But it works only for the first entry in the loop.
for (var i=0; i < len; i++)
{
var node = nodes.getNode(i);
m_strResult = m_strResult + node.get_text();
var objChkBox = node._checkBox;
m_strResult = m_strResult + " : " + node.get_selected() + "\n";
}
Here objChkBox is null from the second node in the tree.
Also from the objChkBox object how do I know if the checkbox is selected?
Please let me know what I am missing.
Thanks
Prasad
you can get all the checked nodes in the tree by calling tree.get_checkedNodes(). It will return an array of $IG.Node objects.Then on each node you can call node.get_checkState() which can return 0-Unchecked, 1-Checked, 2-Partial depending on the check box mode you have configured.
Hope this helps.
Thanks,
Lubomir
Lubomir,
What might I be missing here?
I'm assuming that you're working the "tree.get_checkedNodes()" in JavaScript. But when I use it, I get an "Object doesn't support this property of method" JScript runtime error.
Pertinent parts of my code:
<ig:webdatatree ID="tvwUserGroups" runat="server" InitialExpandDepth="2" EnableExpandOnClick="true" InitialDataBindDepth="2" EnableSingleBranchExpand="true" EnableConnectorLines="true" AutoPostBackFlags-NodeClick="on" CheckBoxMode="BiState" DataLoadingMessage="Loading...Please be patient" ViewStateMode="Enabled">
<DataBindings><ig:datatreenodebinding DataMember="dtGroups" TextField="Name" ValueField="Guid" /> </DataBindings>
</ig:webdatatree>
BLOCKED SCRIPT
function GetUserGroups() {
var nodes = new Array;
var tree = document.getElementById('<%= tvwUserGroups.ClientID %>');
nodes = tree.get_checkedNodes();
var userGroupGuid = "";
for (var i = 0; i < nodes.length; i++) {
if (nodes[i].get_checkState == 1) {
if (userGroupGuid.length > 0) {
userGroupGuid += "|";
userGroupGuid += nodes[i].value;
document.getElementById('<%= hdnUserGroupList.ClientID %>').value = userGroupGuid'
} // end function
The point of this whole exercise is that I have a tree of Active Directory Groups and the Users who belong to those groups. The user can select one or more Groups and/or Users by checking the appropriate checkboxes, then clicking an "Assign" button. The Idea is to walk the tree and collect the checked nodes so that those Groups and Users can be granted access to the assigned stuff.
I tried walking the tree on the server side, but none of the nodes showed up as checked. I figure now I need to collect the data on the client side and pass it to the server with a Hidden Control.
Any other thoughts would be much appreciated.
Thanks in advance,
Michell
I'm using v10.2.
By the way, I found a workaround that solves the problem:
tree_NodeChecking
I'm keeping track of whenever a user checks or unchecks a node, then gather up the data later for processing.
this error is returned when the tree instance is null or the object doesn't have such function. Try using the following code var tree = $find("<%= dtWithContext.ClientID %>"); If it still doesn't work you are probably using some old version of the code. Which build are you using?