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

Enable/Disable some nodes on load.

4 Answers 886 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 01 Jul 2015, 05:29 AM

Hi,

I have the following code that runs on the check event of the Kendo TreeView CheckBox. If the node is checked, it disables and unchecks all of its children nodes. If the node is unchecked, it simply enables the children. I would like to perform similar functionality in the document.ready section, where I need to go over all the tree nodes, and disable all children of any checked node. While it seems simple, I cannot wrap my head around the right traversal method for this to work.

Please advise.
Thanks.
Alex.

 

function onCheck(e) {
 
    var chbx = $(e.node).find('.k-checkbox input').filter(":first");
    var state = chbx.is(':checked');
 
    if (state) {
        $(e.node).find(".k-group input").prop('checked', false);
        $(e.node).find(".k-group input").prop('disabled', true);
 
    } else {
        $(e.node).find(".k-group input").prop('disabled', false);
 
    }
}

4 Answers, 1 is accepted

Sort by
0
TorgueFan
Top achievements
Rank 1
answered on 02 Jul 2015, 11:30 PM
Hi Alex,

Take a look at this example.  The following code will provide you with details on how to fix your problem, although you may have to tweak it to work into your own code.

1. Click on the example.

2. Click run.

3. Click a checkbox.

The onCheck function will iterate through the children objects and determine to enable or disable them based on the conditionals.
The correct approach to disable and enable is .set("enabled", false);  Check this link out for more information on enable.

Hope this helps!
0
Alex
Top achievements
Rank 1
answered on 04 Jul 2015, 07:08 PM

Thanks TorgueFan,

I will try that and see how it goes. on a related note, how can I iterate over the nodes without the "e" argument? The "e" argument gives a handle to the firing node, which you can use as an anchor to get to the other nodes. If I want to replicate this functionality in, say, the document.ready event, I will not have access to "e". So, how can get access to the nodes in a hierarchical fashion.

Thanks again.
Alex.

0
TorgueFan
Top achievements
Rank 1
answered on 06 Jul 2015, 05:09 PM
Here's an example to solve your problem. First, we get a reference to the treeview using jQuery. 
Next, using the view method, we can get the nodes. Finally, we iterate through the nodes.

You will still need to do a little work to use it in your application.

Good luck!
0
Alex
Top achievements
Rank 1
answered on 06 Jul 2015, 07:50 PM
TorgueFan,

This is exactly what I needed.

Thank you very much.
Regards.
Alex.
Tags
TreeView
Asked by
Alex
Top achievements
Rank 1
Answers by
TorgueFan
Top achievements
Rank 1
Alex
Top achievements
Rank 1
Share this question
or