开发者

GXT Treepanel checkbox cascade not working from leaves up

开发者 https://www.devze.com 2023-02-15 19:58 出处:网络
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 node

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消