Search code examples
javagwtgxttreegrid

GXT: How to set Checkbox TreeGrid item initially checked?


I'm developing an GIS app which can have map layers turned on by default. When layer is on, the checkbox of the Checkbox TreeGrid should be checked.

I've tried to add "checked" field to my tree's BaseModel:

public boolean getChecked() {
    return (Boolean) get("checked");
}

public void setChecked(boolean b) {
    set ("checked", true);
}

But it hasn't give any results. How can I set checkboxes of CheckboxTreeGrid initially checked?


Solution

  • I've figured it out.

    The following code should be fired in in Events.ViewReady event of Checkbox TreeGrid, because nodes in tree root won't be rendered before. Then expandAll() is used to render all tree children. Variable checkedItems contains a List items which you want to be checked on the tree.

    be.getTreeGrid().expandAll();
    be.getTreeGrid().setCheckedSelection(checkedItems);
    be.getTreeGrid().collapseAll();