Enable/Disable some nodes on load.

5 posts, 0 answers
  1. Alex
    Alex avatar
    3 posts
    Member since:
    May 2015

    Posted 01 Jul 2015 Link to this post

    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);
     
        }
    }
  2. TorgueFan
    TorgueFan avatar
    6 posts
    Member since:
    Jun 2015

    Posted 02 Jul 2015 in reply to Alex Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Alex
    Alex avatar
    3 posts
    Member since:
    May 2015

    Posted 04 Jul 2015 Link to this post

    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.

  5. TorgueFan
    TorgueFan avatar
    6 posts
    Member since:
    Jun 2015

    Posted 06 Jul 2015 in reply to Alex Link to this post

    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!
  6. Alex
    Alex avatar
    3 posts
    Member since:
    May 2015

    Posted 06 Jul 2015 in reply to TorgueFan Link to this post

    TorgueFan,

    This is exactly what I needed.

    Thank you very much.
    Regards.
    Alex.
Back to Top
Kendo UI is VS 2017 Ready