pjekel / cbtree

The Dijit Tree with Multi State Checkboxes, project code 'cbtree' , is a highly configurable dojo/dijit tree with support for multi-state checkboxes or third party widgets capable of presenting a so-called 'checked' state.
Other
75 stars 34 forks source link

expandChecked() #36

Closed pccolella closed 11 years ago

pccolella commented 11 years ago

Hi,

This is a great tool! I'm trying to expand all branches which have checked leafs. I thought the expandChecked() function may be the solution but it doesn't seem to do that.

Code is fairly simple and using dojo 1.9.1

                    cbtStore = new cbtHierarchy({
                        url: treeUrl,
                        idProperty: "id"
                    });
                    cbtModel = new cbTreeStoreModel({
                        store: cbtStore,
                        //checkedAll: false,
                        checkedAttr: 'event_id',
                        multiState: true,
                        query: {parent: 0}
                    });
                    cbtTree = new cbTree({
                        model: cbtModel,
                        checkBoxes: true,
                        persist: false,
                        branchReadOnly: true,
                        autoExpand: false,
                        openOnChecked: true,
                        icon: "fileIcon"
                    }, "standardsTree");

                    cbtTree.expandChecked();

Any guidance would be greatly appreciated.

pjekel commented 11 years ago

I was able to reproduce and fix the issue. In your example you explicitly set the checkedAttr property on the model, however, both the expandChecked() and collapseUnChecked() methods looked for a checked property (e.g the default value of checkedAttr).

The issue has been fixed and checked in to github. Please fetch the updated Tree.js module from github and let me know if this fixed the issue for you.

(No download package with the fix available yet).

pccolella commented 11 years ago

Thank you I understand your changes. I've updated my Tree.js and unfortunately my tree does not expand to checked leafs. I've also tried tried changing my store object property from 'event_id' to 'checked' and have removed the checkedAttr in the Model and although the leaf does get checked properly, the expandChecked function still does not work. But thank you for your help.

pccolella commented 11 years ago

The solution I found to this is:

Model should have: checkedRoot: true otherwise by default the root is not getting a checked state

Also, there seems to be a timing issue with calling expandChecked directly after the creation. Perhaps the delay in loading data via a URL is an issue. Instead by setting: openOnChecked: true in the tree properties, there is no need to call expendChecked as this will occur properly after the tree is loaded.

Thanks for your help.

pjekel commented 11 years ago

I have tweaked the expandChecked() method a little more to account for tree's that don't have a root checkbox. In addition, I also added a new property to the tree, branchCheckBox which will offer the ability to hide checkboxes associated with branch nodes.

To account for any delays due to loading the store using a URL you should do the following:

tree.on("load", function () {
   this.expandChecked();
});

I checked in the tree update, and added documentation for the branchCheckBox property. Please fetch Tree.js from github and give it a try.

Please let me know if this fixes your issue(s).