Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Override the expansion component in treegrid

    Hi,
    How can I override the expansion component in treegrid. I want to load the data in treegrid when the user clicks on the "+" sign. Please let me know is there any approach that I can use to work.

    Thanks in advance for any help.

    Thanks

    #2
    Hi

    I am pasting here a startup code to fetch data for a tree when you click on the plus icon of a node. Initially it will fetch only top level nodes. When you click on the plus icon it will call your service to fetch more data. For example if your service url is http://127.0.0.1:8888/test/ideaXML then it will be called with parentID parameter like this http://127.0.0.1:8888/test/ideaXML?parentId=64 where 64 is the id of node on which yo had clicked.

    Code:
    TreeGrid myTree = new TreeGrid();
    
    		myTree .setLoadDataOnDemand(true);
    		myTree .setWidth(300);
    		myTree .setHeight100();
    		myTree .setAutoFetchData(true);
    		myTree .setDataSource(getDS());
    		myTree .setShowConnectors(true);
    		myTree .setCanSort(false);
    		myTree .setShowOpenIcons(true);
    		myTree .setShowDropIcons(false);
    		myTree .setClosedIconSuffix("");
    		myTree .setFields(new TreeGridField("text", "Tree title"));
    
    		myTree .addDataArrivedHandler(new DataArrivedHandler() {
    
    			@Override
    			public void onDataArrived(DataArrivedEvent event) {
    				SC.say("Data arrived");
    
    			}
    		});
    
    		myTree .addFolderClickHandler(new FolderClickHandler() {
    
    			@Override
    			public void onFolderClick(FolderClickEvent event) {
    				SC.say("Folder clicked, get more data");
    
    			}
    		});
    		myTree .addLeafClickHandler(new LeafClickHandler() {
    
    			public void onLeafClick(LeafClickEvent event) {
    
    				SC.say("Navigation target (  clicked.");
    			}
    
    		});
    
    		addMember(menuTree);
    
    		this.draw();
    	}
    
    	private DataSource getDS() {
    		DataSource ds = new DataSource();
    
    		ds.setDataFormat(DSDataFormat.JSON);
    		ds.setDataURL("myservlets/ideaXML");
    		ds.setChildrenField("item");
    
    		DataSourceTextField idField = new DataSourceTextField("id", "ID");
    		idField.setPrimaryKey(true);
    		idField.setRequired(true);
    		idField.setRootValue("0");
    
    		DataSourceTextField displayedNameField = new DataSourceTextField(
    				"text", "Displayed Name");
    		displayedNameField.setRootValue("Ideas");
    
    		ds.setFields(new DataSourceField[] { idField, displayedNameField });
    		return ds;
    	}
    Last edited by swardi; 11 Jun 2010, 07:33. Reason: forgot to put code tag

    Comment


      #3
      Thanks you verymuch Swardi.

      Comment

      Working...
      X