Announcement

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

    server code for scroll-based paging

    Hi,

    I have a furtherquestion about implementing scroll-based paging.

    I have set my dataPageSize on my list grid to 50 like so:
    Code:
    dataPageSize: 50
    And, in my Server Side controller, I have the following logic to get the start and end row from the request and pass it to my Database:

    Code:
    // DataSource protocol: get requested row range
    int startRow = (int)dsRequest.getStartRow();
    int endRow = (int)dsRequest.getEndRow();
    	        
    bean.setFundAssetDTOList(this.fundAssetService.findFundAssetList(faDTO, startRow, endRow));
    However, this simply returns 50 rows and never fetches successive pages to display in my grid. Is there something I'm missing either server side or client side to enable paging in my grid?

    #2
    You need to set dsResponse.totalRows to advertise to the grid/ResultSet that more rows are available (this is how the scrollbar thumb gets sized). In the absence of a value for totalRows, the ResultSet assumes all rows have been returned, hence the behavior you are seeing.

    Comment


      #3
      Thanks, sounds simple enough. Do I need to return TotalRows from the server as part of each paging request? Or, just the initial fetch? It seems like that would be extra (and unnecessary) server work to calculate the total rows for each paging request but not sure if there is any way around it?

      Comment


        #4
        totalRows is expected to be set each time, in fact, if totalRows changes a ResultSet in paging mode will automatically drop cache on the assumption that a concurrent update has occurred.

        If you aren't concerned about concurrent modification in your application, you could pass the client's value of "totalRows" (effectively, resultSet.getLength())to the server with every fetch request, and simply have the server use that value.

        It would be somewhat involved to pull this off generically, however, in outline, you could use dataSource.resultSetClass so that you can implement a custom subclass of ResultSet that overrides setCriteria() and always adds the current length (if known) to the criteria.

        Comment


          #5
          Hi,

          I'm still working on this but it's not quite right yet. I am now setting dsReponse.totalRows() correctly. But, what I'm seeing is that a request for the next "page" of data is somehow getting made automatically? I thought that the successive pages of data would only be fetched if the user attempted to scroll down. Is there another property I need to set so that pages are only fetched when the user attempts to scroll down? Or, have I possibly mis-configured something?

          Comment


            #6
            Hi senordhuff,

            Possibly you have an off-by-one? Note the following from the JavaDoc for DSRequest:

            Note that startRow and endRow are zero-based, so startRow: 0, endRow: 1 is a request for the first two records.
            If that's not it, I recommend watching the logs for the request and response for DataSources using the SmartClient built-in SQL connectors, to see if your request differs You might also try temporarily pointing your grid at a sample DataSource from the SDK to eliminate any client-side issues.

            Comment

            Working...
            X