I am using a GXT TreePanel with checkboxes and have noticed that there does not seem to be a way to configure it so that check state 开发者_StackOverflowproperly cascades UP from leaves to parent nodes...example:
foo bar baz Initial state: nothing checked. Input: check bar, then baz. Expected result: foo gets checked to reflect that all its child nodes are checked. Actual result: foo remains unchecked.
You can manually check if all children are checked and then, again manually, set their parent's state accordinaly. The code would be something like this:
tree.addCheckListener(new CheckChangedListener<ModelData>() {
public void checkChanged(CheckChangedEvent<ModelData> event) {
ModelData lastParent = null;
for (ModelData item : tree.getCheckedSelection()) {
BaseTreeModel btm = (BaseTreeModel)item;
if (lastParent != null && btm.getParent() == lastParent) {
continue;
}
boolean allChildrenChecked = true;
for (ModelData modelData : btm.getParent().getChildren()) {
if (!tree.isChecked(modelData)) {
allChildrenChecked = false;
break;
}
}
tree.setChecked(btm.getParent(), allChildrenChecked);
lastParent = btm.getParent();
}
}
});
use setCheckStyle(CheckCascade.CHILDREN);
method.
it will help you.
精彩评论