Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

Timing Issue With ListGrid.getRecords()

$
0
0
We are having an apparent timing problem with a client only DataSource that backs a ListGrid. Our application lists spatial features in the ListGrid. We get the list of features that match current criteria by calling getRecords() on the ListGrid so we can draw them on a geographic map. The problem is that often the getRecords() call happens before the ListGrid is finished showing matching records after an update, so it returns nothing.

We tried using the DSCallback argument to ListGrid.filterData() but the callback still fires before the ListGrid update finishes, causing no data to be returned from getRecords(). Also, sometimes after reapplying the filter, the callback never fires at all.

Here's a summary of what we're doing:
Code:

1) Set everything up.
final protected ListGrid summaryTable = new ListGrid();
final protected DataSource detailsDataSource = new DataSource();
detailsDataSource.setClientOnly( true );
detailsDataSource.setCacheAllData( false );
summaryTable.setAutoFetchData( true );
summaryTable.setDataSource( detailsDataSource );
final DetailViewer itemViewer = new DetailViewer();
itemViewer.setDataSource( this.detailsDataSource );

2) Load the DataSource with data.
detailsDataSource.invalidateCache(); // To remove any data from a prior update
summaryTable.fetchData(); // Clear the ListGrid
for(each new record to be loaded)
{
        ListGridRecord record = new ListGridRecord();
        for(each field on the record)
        {
                record.setAttribute( fieldName, fieldValue );
        }
        detailsDataSource.addData( record );
}

3) Refresh the map.
criteria = new AdvancedCriteria(...); // in case the user changed the criteria
summaryTable.invalidateRecordComponents();
summaryTable.filterData( criteria );  // Tried using a DSCallback here but didn't help
ListGridRecord[] recs = summaryTable.getRecords();
Draw returned features on the map

The simplest scenario that illustrates the problem is that the first time through, step 3 above executes before the ListGrid shows results, so the map is empty (because getRecords returned nothing). Then if step 3 executes again (e.g. due to a change in criteria) then (usually) we get the correct results from getRecords and the map is drawn correctly.

Is there a different callback or a different approach we should be using, so that our getRecords() call doe not happen until the ListGrid has completed applying the updated criteria?

Thanks much!
-Bill Compton

SmartClient Version: v9.0p_2013-10-08/LGPL Development Only (built 2013-10-08)
Firefox 24.5 (needs to be older version for security constraints)

Viewing all articles
Browse latest Browse all 4756

Trending Articles