Go Back   SmartClient Forums > Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17th May 2012, 03:52
billw billw is offline
Registered Developer
 
Join Date: Jul 2011
Posts: 43
Default Refreshing ListGrid visible rows

I'm using a SmartClient (SNAPSHOT-2011-01-06) ListGrid with a custom DataSource. Everything works fine, but after an initial fetch of data into the view, I need to periodically update it to reflect changes on the server. I've searched the forum but not found a clear answer.

The ListGrid fetched data in pages (default page size = 75) which is fine. Ideally, once the user scrolls to a given section, I only need to update the visible rows. I certainly could query the list grid for the visible rows and fetch the data myself (calling the method my custom data source uses), but is there a way to get the ListGrid to do this itself? When my update timer fires, the only way I can get a refresh is:

myGrid.invalidateCache();
myGrid.fetchData();

But this causes the grid to clear, and totally refresh. If the user scrolled down to a certain section of the data, this forces it to clear and scroll back to the top. I want the visible rows only refreshed in-place. If I call just fetchData(), it only fetches the first time, not after that because it already has the data. It does not re-fetch. Any suggestions?

Thanks,
Bill

Last edited by billw; 17th May 2012 at 03:54..
Reply With Quote
  #2  
Old 17th May 2012, 05:42
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,561
Default

There's a complete sample of doing this on the public wiki (wiki.smartclient.com).
Reply With Quote
  #3  
Old 17th May 2012, 14:42
billw billw is offline
Registered Developer
 
Join Date: Jul 2011
Posts: 43
Default

Quote:
Originally Posted by Isomorphic
There's a complete sample of doing this on the public wiki (wiki.smartclient.com).
Thanks. That worked. My updateView method became:

Code:
    this.updateView = function () {
        if (!initialUpdate) {
            dataGrid.invalidateCache();
            dataGrid.fetchData();
            initialUpdate = true;
        }
        else {
            var gridDS =  dataGrid.getDataSource();
            var request = {
                startRow : 0,
                endRow: (dataGrid.getVisibleRows()[1] + dataGrid.data.resultSize),
                sortBy: dataGrid.getSort(),
                showPrompt: false
            };
            var callback = function(dsResponse,data,dsRequest) {
                var resultSet = isc.ResultSet.create({
                    dataSource: dataGrid.getDataSource(),
                    initialLength: dsResponse.totalRows,
                    initialData: dsResponse.data,
                    sortSpecifiers: dataGrid.getSort()
                });

                dataGrid.setData(resultSet);
            };
            gridDS.fetchData(dataGrid.getCriteria(), callback, request);
        }
        startViewTimer();
    };
But this seems like a pretty common use case. Would this be worth adding to the ListGrid? Like "ListGrid.doRefresh()" ??
Reply With Quote
  #4  
Old 17th May 2012, 14:48
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,561
Default

Yes, that's where it's headed, we put such things on the wiki first so people can use them without switching to a development build.
Reply With Quote
  #5  
Old 19th May 2012, 04:38
billw billw is offline
Registered Developer
 
Join Date: Jul 2011
Posts: 43
Default

After examining this more carefully, although this example works, I am not sure it is working the way I expected.

When a ListGrid is connected to a DataSource, it coordinates the fetching and paginating the data based on the totalRows that it received in a DSResponse, and it creates and manages the ResultSets. In this example, the startRow is always 0. Isn't this the way a ListGrid would normally do it's fetch for initialData? If the actual data totalRows = 1000, and the ListGrid was scrolled to the bottom, this would cause all data to be fetched, which is not good. Can I just set the startRow to the first visible row, or will that interfere with however the ListGrid would normally manage its ResultSet when it first scrolled to a new position towards the end of the total data rows?
Reply With Quote
  #6  
Old 26th Apr 2013, 04:26
billw billw is offline
Registered Developer
 
Join Date: Jul 2011
Posts: 43
Default

At the time I first posted this, I was using an older version of SmartClient. Now using 8.3 (or possibly 9.x), and the new application still has the need to periodically refresh the visible rows of ListGrids. I see there is a refreshRow(N) method--not sure if this was there in the earlier version. I assume I could get the visible rows and do a refreshRow on each. But I believe this would cause a fetch from the server via the dataSource for each row. It would be great if there were a refreshVisibleRows() that would cause the grid to fetch the appropriate rows in one shot. Or is there a better way?
Reply With Quote
  #7  
Old 26th Apr 2013, 10:51
Isomorphic Isomorphic is offline
Administrator
 
Join Date: May 2006
Posts: 30,561
Default

refreshRow() is a longstanding API and does only what it says: redraws the visual appearance of the row, with no server fetch involved.

For a background refresh of all rows in the viewport, the method on the wiki is still the right approach.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display data in ListGrid with specific number of rows rocket Smart GWT Technical Q&A 4 31st Aug 2011 06:36
Synthetic ListGrid rows aarontsmith Smart GWT Technical Q&A 4 12th May 2011 09:05
Hiding/filtering ListGrid rows tprokuski Smart GWT Technical Q&A 0 23rd Mar 2010 07:02
refreshing all listgrid rows at once lchen Technical Q&A 1 11th Mar 2010 09:49
refreshing all listgrid rows at once lchen Technical Q&A 0 11th Mar 2010 09:47

© 2010,2011 Isomorphic Software. All Rights Reserved