Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
How to set true to all nodes in javascript
posted

Hi, i was trying to develop a client side script that should check all nodes if the "Select All" checkbox is checked. 

The nodes are still not checked after this script being executed in the NodeChecking event handler.

<igtree:WebDataTree ID="wdtProcesses" runat="server" CssClass="ProcessesWebTree"
EnableAjax="true" AjaxIndicator-Enabled="True" DragDropSettings-EnableDragDrop="false"
NodeEditing-Enabled="false" CheckBoxMode="BiState">
<Nodes>
</Nodes>
<NodeSettings CssClass="ProcessExplorerNodeStyle" HoverCssClass="ProcessExplorerHoverNodeStyle"
SelectedCssClass="ProcessExplorerSelectedNodeStyle" />
<ClientEvents NodeChecking="NodeCheckedBoxHandler" />
</igtree:WebDataTree>


function NodeCheckedBoxHandler(sender, args) {

var node = args.getNode();
var wdt = $find("<%=wdtProcesses.ClientID %>");

if (node.get_text() == 'Select All') {

for (var i = 0; i < wdt.getNodes().get_length(); i++)
{

var rootNode = wdt.getNodes().getNode(i);
rootNode.set_selected = true;


}
}
}

Parents
No Data
Reply
  • 8421
    Suggested Answer
    posted

    Hello,

    Rather than using set_selected you should use set_checkState. As a note, both of these are functions so you should be passing a value in rather than setting it equal to some value. For set_checkState it accepts a value of 0 for unchecked and a value of 1 for checked. Your modified code would look something like the following:

    Code Snippet
    <script>
        function NodeCheckedBoxHandler(sender, args) {
            var node = args.getNode();
            var wdt = $find("<%= tree.ClientID %>");

            if (node.get_text() == 'Select All') {
                var newCheckState = node.get_checkState() === 0 ? 1 : 0,
                    nodes = wdt.getNodes(),
                    nodeCount = nodes.get_length();

                for (var i = 1; i < nodeCount; i++) {
                    var rootNode = nodes.getNode(i);
                    rootNode.set_checkState(newCheckState);
                }
            }
        }
    </script>

    Please let me know if you have any questions or concerns about this implementation.

Children
No Data