Announcement

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

    completely flicker free ListGrid update

    Hi all,

    I'm trying to achieve the effect of a completely prompt/message/flicker free ListGrid refresh from a DataSource. I've scoured the forums for hints and tips on this. The DS I'm using is a GwtRpcDataSource. It retrieves the first 100 records from a DB. The grid is read only.


    Below is my approach:
    Code:
    private RecordList recordList = new RecordList();
    
    ...
    grid = getListGrid();
    grid.setAutoFetchData(false);
    grid.setShowAllRecords(true);
    grid.setData(recordList);
    
    final DSRequest reqProp = new DSRequest();
    reqProp.setShowPrompt(false);
    
    final RefreshCallback callback = new RefreshCallback();
    
    Timer timer = new Timer() {
    	@Override
    	public void run() {
    		Criteria criteria = new Criteria();
    		criteria.setAttribute("cachebuster", (new Date()).getTime());				
    		grid.fetchData(criteria, callback, reqProp);
    	}
    };
    timer.scheduleRepeating(5000);

    Code:
    private class RefreshCallback implements DSCallback {
    	@Override
    	public void execute(DSResponse response, Object rawData, DSRequest request) {
    			
    		if (recordList.isEmpty()) {
    			recordList.addList(response.getData());
    			System.out.println("initial set");
    
    		} else {
    			for (int x=0; x<response.getData().length; x++) {					
    				Record record = response.getData()[x];
    
    				// grow recordlist?
    				if (recordList.get(x) == null) {
    					System.out.println("added");
    					recordList.add(new Record());
    				}
    	
    				recordList.get(x).setAttribute(
    						someFieldName1, 
    						record.getAttribute(someFieldname1));
    				// repeat for other fields...
    			}
    
    			// shrink record list?
    			if (recordList.getLength() > response.getData().length) {
    				for (int x=response.getData().length; x<recordList.getLength(); x++) {
    					recordList.removeAt(x);
    					System.out.println("removed pos "+x);
    				}
    			}
    		}
    	}		
    }
    This was inspired by sanjiv's post here: http://forums.smartclient.com/showth...fresh+listgrid, and I can see the records on the ListGrid refreshed completely silently. Other approaches I've read about refreshes the grid (via setData) but still shows the "loading" message.

    This approach works mostly, however:

    1) Occasionally, I still see the "Loading..." message (the one that is set by setLoadingDatamessage), and I cannot pinpoint when or what causes this to happen
    2) When running in Chrome, the "loading" message still appears on each refresh, albeit very briefly. In FF I cannot see it.
    3) I lose the focus on the currently selected row.

    Is there a simpler way to achieve this? Or do I have to do something more complicated and do a cell-by-cell comparison to update data?

    My setup in GWT 2.0.3, SmartGWT 2.2, FF 3.6, Chrome 5
    Last edited by sunnyl; 5 Jul 2010, 22:59.

    #2
    It seems my previous attempt is not perfect. Something else caused it to appear to be working! The fetchData call itself (with a blank callback) causes the grid to "loading..." without ever calling setData.

    I guess I need to rewind my question: what approach should be taken to achieve a flicker/reload free grid refresh?

    Comment


      #3
      I'm looking for a resolution for this same problem. Did you ever get it working?

      Comment

      Working...
      X