Hi
I'm trying to get a tree with fixed data to allow filtering with a filter editor, keeping the parentnodes on filter. When I try to do this with just setting the data and applying a filter, a javascript error occurs saying getDataSource is not available. Therefore I tried using a dummy clientOnly testdatasource. This has unexpected effects:
- the tree gets flattened, all leafs get the same level as the folder nodes;
- the filter is not applied.
I have adapted the example showcase to reflect what I want to do. I'm sure I'm not using the right combination of setters but am struggling for a while now. Any help would be appreciated.
Thanks, ITB
	
							
						
					I'm trying to get a tree with fixed data to allow filtering with a filter editor, keeping the parentnodes on filter. When I try to do this with just setting the data and applying a filter, a javascript error occurs saying getDataSource is not available. Therefore I tried using a dummy clientOnly testdatasource. This has unexpected effects:
- the tree gets flattened, all leafs get the same level as the folder nodes;
- the filter is not applied.
I have adapted the example showcase to reflect what I want to do. I'm sure I'm not using the right combination of setters but am struggling for a while now. Any help would be appreciated.
Thanks, ITB
Code:
	
	public class Test implements EntryPoint {
    private class PartsDataSource extends DataSource {
        public PartsDataSource() {
            this.setClientOnly(Boolean.TRUE);
            Tree grid1Tree = new Tree();
            grid1Tree.setModelType(TreeModelType.CHILDREN);
            grid1Tree.setNameProperty("Name");
            grid1Tree.setRoot(new PartsTreeNode("Root",
                    new PartsTreeNode("Bin 1",
                            new PartsTreeNode("Blue Cube", "cube_blue.png"),
                            new PartsTreeNode("Yellow Cube", "cube_yellow.png"),
                            new PartsTreeNode("Green Cube", "cube_green.png")
                    ),
                    new PartsTreeNode("Bin 2",
                            new PartsTreeNode("Blue Piece", "pawn_blue.png"),
                            new PartsTreeNode("Green Piece", "pawn_green.png"),
                            new PartsTreeNode("Yellow Piece", "pawn_yellow.png")
                    )
                    ));
            this.setTestData(grid1Tree.getRoot().getAttributeAsRecordArray("children"));
        }
        
    }
    
    @Override
    public void onModuleLoad() {
        
        final PartsTreeGrid grid1 = new PartsTreeGrid();
        ListGridField name = new ListGridField("Name");
        name.setCanFilter(Boolean.TRUE);
        grid1.setFields(name);
        grid1.setShowFilterEditor(Boolean.TRUE);
        grid1.setFilterOnKeypress(Boolean.TRUE);
        grid1.setKeepParentsOnFilter(Boolean.TRUE);
        grid1.setLoadDataOnDemand(Boolean.FALSE);
        // grid1.setFilterLocalData(Boolean.TRUE);
        // grid1.setDataFetchMode(FetchMode.LOCAL);
        grid1.setDataSource(new PartsDataSource());
        grid1.draw();
        grid1.fetchData();
    }
    
    public static class PartsTreeGrid extends TreeGrid {
        public PartsTreeGrid() {
            this.setWidth(300);
            this.setHeight(300);
            this.setShowEdges(true);
            this.setBorder("0px");
            this.setBodyStyleName("normal");
            this.setShowHeader(false);
            this.setLeaveScrollbarGap(false);
            this.setAppImgDir("pieces/16/");
        }
    }
    
    public static class PartsTreeNode extends TreeNode {
        public PartsTreeNode(final String name, final String icon) {
            this(name, icon, new PartsTreeNode[] {});
        }
        
        public PartsTreeNode(final String name, final PartsTreeNode... children) {
            this(name, null, children);
        }
        
        public PartsTreeNode(final String name, final String icon, final PartsTreeNode... children) {
            this.setAttribute("Name", name);
            this.setAttribute("children", children);
            if (icon != null) {
                this.setAttribute("icon", icon);
            }
        }
    }
}