Announcement

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

    Refresh content of an expanded ListGrid record

    In a situation where I have a ListGrid with getExpansionComponent overridden, I would like to refresh the content of the expanded component. I figured that I can refresh a row of a ListGrid using refreshRow, but the grid probably know if it's necessary to update the expanded component as there isn't directly a field related to that. Collapsing the record and expanding it again redraws it ofcourse.

    Take this example:
    Code:
    addChild(grid = new ListGrid() {
    	@Override
    	protected Canvas getExpansionComponent(ListGridRecord record) {
    		/*
    		 * This is just an example of what the expanded content could be
    		 */
    		Canvas c = new Canvas();
    		c.setContents(record.getAttribute("expandedContent"));
    		c.setHeight(20);
    		c.setWidth100();
    		return c;
    	}
    
    	{
    		setWidth100();
    		setHeight100();
    		setCanExpandRecords(true);
    
    		setFields(
    			new ListGridField("id"),
    			new ListGridField("name")
    		);
    
    		/*
    		 * Add some random data
    		 */
    		setData(new ListGridRecord[]{
    			new ListGridRecord() {{
    				setAttribute("id", "1");
    				setAttribute("name", "Row one");
    				setAttribute("expandedContent", "This content is for the expanded component of row one");
    			}},
    			new ListGridRecord() {{
    				setAttribute("id", "2");
    				setAttribute("name", "Row two");
    				setAttribute("expandedContent", "This content is for the expanded component of row two");
    			}}
    		});
    	}
    });
    
    /*
     * After 2 seconds, we'll update some data
     */
    (new Timer() {
    	@Override
    	public void run() {
    		Record r = grid.getRecord(0);
    		r.setAttribute("name", "New name for row one");
    		r.setAttribute("expandedContent", "New content is for the expanded component of row one");
    		grid.refreshRow(0);
    	}
    }).schedule(2000);
    This renders a grid which is expandable, don't mind the content of the expansion component for now :). But as you can see, in a Timer the content is updated which is used in the expanded component - and should also be refreshed.

    Is there a way to redraw the expanded component of a record? I'm using SmartGWT 2.4, which contains SmartClient 8.0 2010-12-31.

    Thanks in advance for your help!!

    #2
    Currently you have to call collapseRecord and then expandRecord to force a new call to getExpansionComponent.

    Comment


      #3
      Thanks, that works. I also figured that you can use getExpansionComponent to set the ID of the expansion component on the record:

      Code:
      record.setAttribute("_expansionComponentID", expansionComponent.getID());
      and later use:

      Code:
      String expansionComponentID = record.getAttribute("_expansionComponentID");
      if (expansionComponentID != null) {
      	Canvas expansionComponent = Canvas.getById(expansionComponentID);
      	if (expansionComponent instanceof (whatever you're expecting)) {
      		// ... do stuff to refresh it
      	}
      }

      Comment

      Working...
      X