PDA

View Full Version : changing tree panel checkbox state in 4.1.1, how?



bimargulies
9 Aug 2012, 6:40 AM
The code below, run on a tree panel with some check boxes, never changes the visual state or fires any handlers. All the recipes I've found deal with much older versions of ExtJS.

Help?



changecheckall: function(panel, value) {
panel.getRootNode().cascadeBy(function(node) {
if (node.data.checked !== undefined && node.data.checked !== null) {
node.data.checked = value;
}
});
}

harman
9 Aug 2012, 7:05 AM
At a very basic level do


treeObj.getSelectionModel().select(record(s),[Boolean (http://docs.sencha.com/ext-js/4-0/#!/api/Boolean) keepExisting],[Boolean (http://docs.sencha.com/ext-js/4-0/#!/api/Boolean) suppressEvent] )

send boolean according to your requirement.

bimargulies
9 Aug 2012, 7:19 AM
Selecting the nodes does not check (or uncheck) the checkboxes. I tried it.

For one thing, the returned selection model is SINGLE. This can't correspond to the checkboxes, since they allow multiple boxes to be selected.

And, the bottom line is that treeObj.getSelectionModel().selectAll(); has no effect whatsoever on the state of the checkboxes.

harman
9 Aug 2012, 7:29 AM
for that you either need to add the Ext.selection.CheckboxModel
or if you can get to node object you can just call

nodeObj.checked=true
And again this is not tested but i hope will work

bimargulies
9 Aug 2012, 7:30 AM
Adding the checkbox model ends up with two sets of checkboxes, the native ones of the tree and the checkbox model. Honestly, I think you are barking up the wrong tree.

bimargulies
9 Aug 2012, 8:28 AM
I have a partial answer to my own question. The code below switches the visual state, but does not fire the event on the panel to inform that anything has changed.



changecheckall: function(panel, value) {
panel.getRootNode().cascadeBy(function(node) {
if (node.data.checked !== null) {
node.set("checked", value);
}
});
}

scottmartin
9 Aug 2012, 8:30 AM
Have a look at:
http://www.sencha.com/forum/showthread.php?149627

Scott

bimargulies
9 Aug 2012, 8:36 AM
Except for the event management ,which also requires:

panel.fireEvent('checkchange', node, value, null);