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

Programmatically set checked state #54

Closed JakeSummers closed 10 years ago

JakeSummers commented 10 years ago

Hi,

Is there a way to programmatically set the state of checked elements?

The workflow that I would like to do is something like the following:

  1. The tree is opened by the user
  2. Some things in the tree are selected by the user
  3. The user interacts with other parts of the application causing the selected state to change. I would now like to update the selected elements in the tree to reflect the new state.

I tried the following:

console.log("Checked State: ", 
    this.metaDataTree.model.getChecked(treeElement)
);

this.metaDataTree.model.setChecked(treeElement, false);

console.log("Checked State (after set): ",
    this.metaDataTree.model.getChecked(treeElement)
);

This prints:

Checked State: false
Checked State (after set): false

The issue is that it doesn't change the state of the checkbox that is displayed to the user. Before running this code the checkbox is checked. After this is run the checkbox is still set.

Any hints on how to do this would be appreciated.

Thanks, Jake

pjekel commented 10 years ago

In your sample code it is not clear what type of object treeElement is or how you acquired it. Assuming treeElement is an instance of TreeNode you could simple change the checked state by calling:

treeElement.set("checked", false);

or, using the model:

tree.model.setChecked(treeElement.item, false);

Notice that when calling the model setChecked() the store item associated with the TreeNode is used as the first argument, not the tree node itself.