Announcement

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

    TreeGrid startEditingNew

    I wanted to start editing a new node when the user clicks a button. I found this article that explains how to do this. I wanted to leave an example here in case anyone wants to achieve this.
    The node would be added to the tree if it's empty or as a child if a node was selected.

    Code:
    private ClickHandler btnAddCategory_onClick=new ClickHandler() {
    		
    	@Override
    	public void onClick(ClickEvent event) {
    		Record newRecord=new Record(JavaScriptObject.createObject());
    		if(grdCategories.getSelectedRecord()!=null){
    			Record selectedNode=grdCategories.getSelectedRecord();
    			newRecord.setAttribute("idParent", selectedNode.getAttribute("id"));
    		}				
    			grdCategories.addData(newRecord, new DSCallback() {
    					
    				@Override
    				public void execute(DSResponse response, Object rawData, DSRequest request) {
    					if(response.getStatus()>=0 && response.getData()!=null &&response.getData().length>0){
    						Record record=response.getData()[0];
    						TreeNode parent=grdCategories.getData().findById(record.getAttribute("idParent"));
    						if(parent!=null){
    							grdCategories.getData().openFolder(parent);
    						}
    						int row=grdCategories.getRecordIndex(record);
    						grdCategories.startEditing(row, 0, false);
    					}
    				}
    			});
    	}
    };
Working...
X