This is a migrated thread and some comments may be shown as answers.

Unchecking a RadTreeNode with jQuery

2 Answers 91 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Derek Hunziker
Top achievements
Rank 1
Derek Hunziker asked on 04 Jun 2009, 02:12 AM
Hi There,

I have a RadTreeView (Q2 2008) inside of an UpdatePanel.  Also inside the UpdatePanel is a button that deletes all the "checked" nodes.

I'm using jQuery to extend the functionality so that all the child nodes get checked and unchecked with the parent node.  If one of the child nodes is unchecked, the parent checkbox is unchecked too (but not the prev and next child checkboxes).  I was able to achieve this using the following code:

function pageLoad() { 
        $('.rtChk').bind('click'function() { 
 
            // Check/uncheck child checkboxes 
            var parentLi = $(this).parents('.rtLI:first'); 
            if ($(this).is(':checked')) 
                $(parentLi).find('.rtChk:not(:first)').attr('checked'true); 
            else 
                $(parentLi).find('.rtChk:not(:first)').attr('checked'false); 
 
            // Uncheck parent checkbox on uncheck 
            var grandParentLi = $(this).parents('.rtLI:first').parents('.rtLI:first'); 
            if ($(this).is(':checked') == false
                $(grandParentLi).find('.rtChk:first').attr('checked'false); 
        }); 
    } 

This code is working out great and when I uncheck one of the child nodes, the parent appears to be uncheck... however, when I click the button to delete all checked nodes, the parent still gets deleted.  I'm thinking that somewhere along the way, the jQuery "uncheck" isn't registering with my asyncronos postback?

I have a RadScriptManager on the page and I've tried registering the script using Page.RegisterStartupScript... but it still doesn't work.

Any suggestions?




2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 Jun 2009, 10:34 AM
Hello Derek Hunziker,

You should use the API of RadTreeView in order to check the nodes. The latter correctly updates the internal state of the treeview. Just checking the checkboxes will not properly persist the checked state of the nodes after postback.

Regards,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Derek Hunziker
Top achievements
Rank 1
answered on 04 Jun 2009, 10:52 PM
Well that was easy... I should have used the API from the get go (much easier than jQuery)

Here's the code I used in case anyone is doing the same.  

function ClientNodeChecking(sender, eventArgs) { 
        var node = eventArgs.get_node(); 
 
        // Check/uncheck all children 
        for (var i = 0; i < node.get_nodes().get_count(); i++) { 
            var child = node.get_nodes().getNode(i); 
            if (node.get_checked()) 
                child.uncheck(); 
            else 
                child.check(); 
        } 
 
        if (node.get_checked()) { 
            var parent = node.get_parent(); 
            // Make sure the node we're checking isn't the root node 
            if (node.get_parent() != node.get_treeView()) 
                parent.uncheck(); 
        } 
    } 

Tags
TreeView
Asked by
Derek Hunziker
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Derek Hunziker
Top achievements
Rank 1
Share this question
or