jstree checkbox manipulation

Ashwin picture Ashwin · Mar 28, 2012 · Viewed 23.7k times · Source

I have a jstree with checkbox for every nodes. I want to achieve the following. Let me know which method or part of api helps us to do that.

  1. I do not want to check any child nodes when parent node is selected. Currently all the children gets selected.
  2. If any child node is checked then check all its parent node. Currently parent nodes get partially checked (square). I want to remove partial selection completely. That is I want to completely alter behavior of jstree checkboxes.

I searched API docs but found nothing.

Answer

chris picture chris · Apr 26, 2012

Take a look at the real_checkboxes options. This might get you started:

        $("#jstree").jstree({
           "checkbox": {
              real_checkboxes: true,
              real_checkboxes_names: function (n) {
                 var nid = 0;
                 $(n).each(function (data) {
                    nid = $(this).attr("nodeid");
                 });
                 return (["check_" + nid, nid]);
              },
              two_state: true
           },
           "plugins": ["themes", "json_data", "ui", "checkbox"]
        })
        .bind('open_node.jstree', function (e, data) {
           $('#jstree').jstree('check_node', 'li[selected=selected]');
        })

You'll probably need to change the bind behaviour so that it checks the parent when a child is checked.