2

I'm using jsTree with the checkbox plugin to show a tree. I'm just using an unordered list (UL, LI) to define my tree, and then:

    $(function() {
        $("#treeId").jstree({
        "themes" : {
            "theme" : "default",
            "dots": true,
            "icons": false
         },
            "plugins": ["themes", "html_data", "checkbox",
                        "ui", "crrm", "hotkeys"]
        });
    });

I use this to generate the tree. I need some way to hide the checkboxes on certain nodes. Ideally, I would add a class to the nodes on which I don't want checkboxes and then use JavaScript to hide them accordingly, but I haven't found a way to do this yet. Some solutions use JSON attributes to identify nodes, but since I'm not using JSON, I'm not sure I can use this method.

I should mention my end goal is to hide checkboxes on all non-leaf nodes, but a generic solution based on class would be more helpful. Or both solutions would be great too :)

Thanks!

Mike

4 Answers 4

8

If you are not making changes to the functionality, and just want to visually hide the checkbox for certain nodes, you should use CSS.

For example, your end goal is to hide checkboxes for all non-leaf nodes, here is the CSS needed to achieve that.

// First hide all checkboxes
ins.jstree-checkbox {
    display:none;
}

// Then display only checkboxes on leaf nodes
li[class~="jstree-leaf"] > a > ins.jstree-checkbox {
    display: inline-block;
} 

Btw might I ask why you cannot use Chrome at work? I used the execellent developer tools in Chrome to help me decipher the jstree styles to figure out the CSS above.

3
  • thanks for the reply. doesn't seem to work though...can you verify you see it working in IE?
    – mike
    Commented Aug 29, 2012 at 19:27
  • ...and as to why we can't use chrome, i can't answer that. our environments are pretty locked down, so we can't really install anything without a lengthy approval process. it is what it is.
    – mike
    Commented Aug 29, 2012 at 19:31
  • I don't know which version of IE you are using, but with the version of jstree I am using, the above works for IE 7-9. Since I don't have access to your environment, I cannot give you cut and paste code. You will have to look at the css styles on your jstree to figure out exactly how to hide the checkboxes, but the general idea is the same regardless.
    – Bojin Li
    Commented Aug 29, 2012 at 20:46
0

Not knowing much about jsTree, it would seem logical to me that you could simply look at DOM in chrome to identify which nodes you want to hide. Or find the specific id or footprint the checkbox plugin creates, for the checkboxes in the DOM. Then once you know this, you can easily enumerate through them and hide them using jQuery or pure javascript.

1
  • wish we could use chrome at work...nothing but ie here :( i'm also very new to jquery...could you possibly post some code?
    – mike
    Commented Aug 29, 2012 at 14:17
0

Finally got this working. I added a class="node" to all nodes where I wanted to hide the checkboxes, then after the tree is loaded I do this bit of javascript:

$(".node").children().hide();

Hope this helps anybody with the same problem.

1
  • as an alternative, or if you're using lazy loading and don't want to keep calling this when you expand a node, ths css works too: .node .jstree-checkbox { display: none !important; }
    – mike
    Commented Oct 17, 2012 at 18:33
0

Simply add in CSS:

.jstree-leaf .jstree-checkbox {
    display: none;
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.