Announcement

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

    Grid refresh in background

    Hi,

    I have a grid that shows a logging table and needs to be refreshed every 5 seconds or so.

    I do this using
    Code:
    dataGrid.invalidateCache();
    And this works, but it clears the grid before the data is fetched from the server.
    The round trip to the server takes about four seconds so I end up with the grid showing the data for a second, then empty with loading message for four seconds.

    Is there a way to only refresh after the data has been fetched?

    Meindert

    #2
    Fetch it with DataSource.fetchData, then call setData from the callback.

    Comment


      #3
      What about paging

      Thanks for the quick response!

      I implemented as you said but am struggling with the DSRequest parameter..
      Code:
      private void refreshGrid(){
        dataGrid.getDataSource().fetchData(dataGrid.getFilterEditorCriteria(), new DSCallback() {
          public void execute(DSResponse response, Object rawData, DSRequest request) {
            dataGrid.setData(response.getData());
          }
        });
      }
      The code above works beautiful but the paging information is not passed through to the datasource on refresh, and the full recordset is returned
      Is there a way to query the current
      request.getStartRow () of the grid?

      The following code (sort of) works for me by jumping back to the top of the list
      Code:
      private void refreshGrid(){
        DSRequest request = new DSRequest();
        request.setStartRow(0);
        //request.setEndRow(dataGrid.getDataPageSize()); dataGrid.getDataPageSize() is null!
        request.setEndRow(75); 
        request.setSortBy(dataGrid.getSort());
      
        dataGrid.getDataSource().fetchData(dataGrid.getFilterEditorCriteria(), new DSCallback() {
          public void execute(DSResponse response, Object rawData, DSRequest request) {
            dataGrid.setData(response.getData());
          }
        }, request);
      }
      Last edited by meindert; 18 Feb 2010, 07:05.

      Comment


        #4
        How about paging/life grid?

        The dataGrid.setData(response.getData()); does not seem to support the paging functionality.
        How would I set the response.getTotalRows() on the grid so it knows that there are more pages?

        Comment


          #5
          Create a ResultSet with initialData and initialLength and setData with that.

          Comment


            #6
            How to use a resultset?

            Where would I find information about this?

            I'm now storing the current page and sort information in a separate object, when I do a refresh the data is requested twice from the server and the grid goes blank when loading the resultset

            Code:
            private void refreshGrid(){
              DSRequest request = null;
              if (paging!=null){
            	request = new DSRequest();
            	//request.setSortBy(dataGrid.getSort());  //TODO, there is a bug here, the request sortby is not set!
            	if (paging.getSortBy()!=null){
            		SortSpecifier sortSpecifier = null; 
            		if (paging.getSortorder().equals(Paging.ASCENDING)){
            			sortSpecifier = new SortSpecifier(paging.getSortBy(),SortDirection.ASCENDING);
            		}else{
            			sortSpecifier = new SortSpecifier(paging.getSortBy(),SortDirection.DESCENDING);
            		}
            		SortSpecifier[] array = new SortSpecifier[1];
            		array[0]=sortSpecifier;
            		request.setSortBy(array);
            	}
              }
            
            
              dataGrid.getDataSource().fetchData(dataGrid.getFilterEditorCriteria(), new DSCallback() {
            	public void execute(DSResponse response, Object rawData, DSRequest request) {
            		if (paging!=null){
            			ResultSet test=new ResultSet();
            			test.setDataSource(dataGrid.getDataSource());
            			test.setInitialData(response.getData());
            			test.setInitialLength(response.getTotalRows());
            			dataGrid.setData(test);
            		}else{
            			dataGrid.setData(response.getData());
            		}
            	}
              },request);
            }
            Is there a example of how to use a SmartGwt resultset?
            Last edited by meindert; 1 Mar 2010, 00:40.

            Comment


              #7
              You need to call setDataSource on the ResultSet or it will not have a way to load further data.

              Comment


                #8
                Hi,

                I also try to use setData(resultSet) on a ListGrid to avoid the visual clearing of the grid.

                If I do a fetch with a startRow greater than 0, I cannot scroll back to the rows before the fetched startRow because the grid and also the scrollbar now starts with first row of the fetched data.

                Is there a solution for that problem available?

                Thanks!
                Last edited by eko; 22 Feb 2010, 16:25.

                Comment


                  #9
                  At the moment, you would need to instead load all the rows up to the last shown row. This could be addressed with a small feature sponsorship, or you could submit a patch yourself.

                  Comment


                    #10
                    Last word

                    As I understand it, it's not wise to have a grid that refreshes every 10 seconds to have more then one page (70 records) of data.

                    Here is my final code I'm using. Basicaly the silent refresh is done when there is only one page, and a full refresh is done when there is more then a page of data;

                    The widget code for refreshing the grid
                    Code:
                    private void refreshGrid(){
                      DSRequest request = null;
                      if (paging!=null && paging.getOnePage()){
                          request = new DSRequest();
                          request.setStartRow(paging.getStartRow());
                          request.setEndRow(paging.getEndRow());
                          //request.setSortBy(dataGrid.getSort());  //TODO, there is a bug here, the request sortby is not set!
                          if (paging.getSortBy()!=null){
                          SortSpecifier sortSpecifier = null; 
                          if (paging.getSortorder().equals(Paging.ASCENDING)){
                            sortSpecifier = new SortSpecifier(paging.getSortBy(),SortDirection.ASCENDING);
                          }else{
                            sortSpecifier = new SortSpecifier(paging.getSortBy(),SortDirection.DESCENDING);
                          }
                          SortSpecifier[] array = new SortSpecifier[1];
                          array[0]=sortSpecifier;
                          request.setSortBy(array);
                        }
                        dataGrid.getDataSource().fetchData(dataGrid.getFilterEditorCriteria(), new DSCallback() {
                          public void execute(DSResponse response, Object rawData, DSRequest request) {
                            dataGrid.setData(response.getData());
                          }
                        },request);
                      }else{
                        dataGrid.invalidateCache();
                      }
                    }
                    The paging class is the global object to keep track of the current page and sort information.
                    The BenchmarkRequestDS class is the GwtRpcDataSource I'm using.
                    Attached Files
                    Last edited by meindert; 1 Mar 2010, 00:33.

                    Comment

                    Working...
                    X