Announcement

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

    Set Focus ListGrid Cell

    Be sure your post includes:

    Greetings,

    We are using SmartGWT Power 2.4. I am not sure if anyone out there has done this yet but any tips would be appreciated.

    I am trying to create embedded component within a List grid. That component has a ListGrid that I wish to set focus to a particular cell. I have searched the forums and came across the
    Code:
    startEditing(rowNum, colNum, suppressFocus)
    method of the ListGrid class and thought that would provide my solution but it does not seem to to work.

    Below is a simplified version of the code I am trying to get working. Essentially I setup a cell click handler on the grid and if a cell in a particular column was clicked I call a method that ultimately creates a grid adds that 2nd grid as the 1st's embeddedComponent. It all works beautifully except getting focus set in the first cell of the first row of the embedded grid. I have tried various enumerations of the
    Code:
    startEditing()
    method but to no avail. Any thoughts would be greatly appreciated.

    Code:
    //Set up the handler to expand and what not
    listGrid.addCellClickHandler(new CellClickHandler() {
    	
    	@Override
    	public void onCellClick(CellClickEvent event) {
    
    		record =  event.getRecord();  
    		int colNum = event.getColNum();
    		int rowNum = event.getRowNum();
    		ListGridField field = listGrid.getField(colNum);  
    		String fieldName = listGrid.getFieldName(colNum);  
    		String fieldTitle = field.getTitle();
    		
    		if(fieldTitle.equalsIgnoreCase("Item")) {
    
    			createItemCellEmbeddedComponent(listGrid, rowNum);
    		}
    	}
    });
    
    private void createSKUCellEmbeddedComponent(final ListGrid listGrid, final int recordNum) {
    	
    	//Get the data source
    	DataSource dataSource = RandomDataXMLDS.getInstance();  
    
    	ListGridField rowNum = new ListGridField("itemNum", "ID");  
    	rowNum.setWidth(65);
    	rowNum.setCellFormatter(new CellFormatter() {  
    
    		@Override
    		public String format(Object value, ListGridRecord record,
    				int rowNum, int colNum) {
    			return rowNum +"";  
    		}  
    	});  
    
    	ListGridField fooField = new ListGridField("foo", 100);
    	ListGridField barField = new ListGridField("bar", 100);
    	ListGridField foobarField = new ListGridField("foobar", 100);
    	
    	ListGrid grid = new ListGrid();
    	grid.setWidth(300);  
    	grid.setHeight100();  
    	grid.setAutoFetchData(true);  
    	grid.setDataSource(dataSource);
    	grid.setCanEdit(true);
    	grid.setAutoFitData(Autofit.HORIZONTAL);
    
    	grid.setFields(rowNum, fooField, barField, foobarField);
    
    	grid.startEditing(0,0,false);
    	
    	VLayout vlayout = new VLayout();
    	vlayout.setShowEdges(true);  
    	vlayout.setMembersMargin(5);  
    	vlayout.setLayoutMargin(10);  
    	vlayout.setWidth(300);
    	vlayout.setHeight(300);
    	vlayout.addMember(grid);
    	
    	//This is where the magic happens, adding the Canvas/Layout/somethat that iherits from Canvas to the list Grid
    	listGrid.addEmbeddedComponent(vlayout, record);
    }

    #2
    I am beginning to think this is not possible, at least "when" I want to get it done. The reason is that it appears that at the time I am trying to get focus within a particular cell in the embedded content ListGrid that grid has not finished drawing and being populated with data.

    I have tried another approach, extending the ListGrid class and overriding it's onDraw and onLoad methods but so far this approach is not yielding success.

    Comment


      #3
      The embedded grid won't be drawn until the outer grid goes through a redraw(). You could make this call manually after calling addEmbeddedComponent(), or just add a DrawHandler to your embedded grid and call startEditing then.

      Comment


        #4
        I have tried adding a DrawHandler to the embedded grid via addDrawHandler, but that did not fully realize what I am hoping to get. I then tried a variety of other handlers and finally came across one that does what I want but I think will be problematic if there is large enough dataset that requires subsequent calls get data for the grid is concerned, like scrolling etc. That handler is the DataArrivedHandler.

        Essentially what I believe the difference is between the two above mentioned handlers is that the DrawHandler is fired prior to the grid getting populated with data from my datasource and the DataArrivedHandler "works" because it is called after the data has been loaded into the grid.

        I have attached two images, addOnDrawHandler.png and addOnDataArrivedHandler.png to show the difference that I am seeing where the focus is placed in the grid.

        Thoughts anyone?
        Attached Files

        Comment


          #5
          Yes, if the embedded grid is doing a fetch against a separate DataSource, DataArrivedHandler (on the embedded grid) is the right one to use.

          DrawHandler would be the right one to use if the embedded grid was provided data before it was added as an embedded component.

          Comment

          Working...
          X