In Checkbox Tree while getting selected nodes, it return partial selected nodes also.
In following sample code when I click on ‘C1’ node, it partially select its parent node as well which is correct behavior.
But for ‘getSelection’ method it returns ‘C1’ along with its parent.
Here I dont want to get parent node in selection as it is partially selected.
How to get only selected nodes?
import com.google.gwt.core.client.*;
import com.smartgwt.client.types.*;
import com.smartgwt.client.widgets.grid.*;
import com.smartgwt.client.widgets.layout.*;
import com.smartgwt.client.widgets.tree.*;
public class test implements EntryPoint
{
private TreeGrid counterTree;
private String ST_COUNTER = "Counter";
public void onModuleLoad()
{
counterTree = new TreeGrid();
counterTree.setWidth(400);
counterTree.setHeight(400);
counterTree.setShowSelectedStyle(false);
counterTree.setShowPartialSelection(true);
counterTree.setCascadeSelection(true);
counterTree.setSelectionAppearance(SelectionAppearance.CHECKBOX);
TreeGridField counterColumn = new TreeGridField(ST_COUNTER);
counterTree.setFields(counterColumn);
fillTree();
showSelected();
VLayout mainLayout = new VLayout(10);
mainLayout.addMember(counterTree);
mainLayout.draw();
}
private void fillTree()
{
final Tree tree = new Tree();
tree.setModelType(TreeModelType.PARENT);
TreeNode parent = new TreeNode();
parent.setAttribute(ST_COUNTER, "root");
tree.setData(new TreeNode[]{parent});
counterTree.setData(tree);
TreeNode node1 = new TreeNode();
node1.setAttribute(ST_COUNTER, "Node1");
tree.add(node1, parent);
TreeNode c1 = new TreeNode();
c1.setAttribute(ST_COUNTER, "C1");
tree.add(c1, node1);
TreeNode c2 = new TreeNode();
c2.setAttribute(ST_COUNTER, "C2");
tree.add(c2, node1);
tree.openAll();
}
private void showSelected()
{
ListGridRecord rec[] = counterTree.getSelection();
for(int i=0; i<rec.length; i++)
{
rec[i].getAttribute(ST_COUNTER);
}
}
}