Announcement

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

    paging on listgrid

    Using smartgwt 2.5. Opened in firefox 7.0

    Hi i tried to use the paging capability on list grid.
    I tried with setting the page size as very small
    articleListRender.setDataPageSize(3);
    However i found the list grid still loads all records instead of just loading 3.

    This is the way we call fetch data.

    articleListRender.fetchData(c, new DSCallback() {

    @Override
    public void execute(DSResponse response, Object rawData, DSRequest request) {
    System.out.println("after fetch, start:" + response.getStartRow() + ", end:" + response.getEndRow() + ", total:" + response.getTotalRows());

    }
    });

    The print out shows the response contains 4 hundreds records.

    Is there anything we could miss?

    Thanks

    #2
    There are a number of settings that force a fetch of all rows, such as showAllRecords:true, dataFetchMode:"basic", or auto-sizing settings like autoFitData.

    Comment


      #3
      Hi thank you for the reply.

      I found that we need to do some handling in DMI too. (make it not always returning all the records)

      However i found the grid won't keep fetching data on the demand when i scroll down.

      I referenced this example http://www.smartclient.com/smartgwt/showcase/#grid_adaptive_filter_featured_category

      It is also not setting anything else. Is there any way i can enable the paging on scrolling behavior?

      Thanks

      Comment


        #4
        All you have to do is return correct values for startRow, endRow and totalRows. You can use the RPC tab of the Developer Console to see what you've returned.

        Comment


          #5
          Hi,

          Thank you for the reply.
          Do u mean i don't need to do anything from DMI such as only getting a certain range of records?

          Instead just setting those properties in DSResponse when returning from executeFetch?

          Thanks

          Comment


            #6
            You need to return a DSResponse containing your data as the data, and correct settings for startRow, endRow and totalRows.

            Comment


              #7
              Hi,

              Thank you again for the reply.

              Here is my code in the server side

              public DSResponse executeFetch(DSRequest req) throws Exception {
              List records = fetchRecords(req.getCriteria(), req);
              DSResponse response = new DSResponse(records);
              response.setStartRow(req.getStartRow());
              response.setEndRow(req.getEndRow());
              response.setTotalRows(records.size());
              return new DSResponse(records);
              }

              Here is my fetch in the client side
              articleListRender.fetchData(c, new DSCallback() {

              @Override
              public void execute(DSResponse response, Object rawData, DSRequest request) {
              String preViewState = preference.get(Integer.toString(subjectQueryID));
              System.out.println("request- start:" + request.getStartRow() + ", end:" + request.getEndRow());
              System.out.println("response- start:" + response.getStartRow() + ", end:" + response.getEndRow());

              }
              });


              The print shows
              request- start:0, end:75
              response- start:0, end:472

              Although the request ranges from 0 to 72, however response has begin to end from 0 to 472.

              Did i set it wrong in the server?

              Thanks

              Comment


                #8
                Yes, you set it wrong. You are returning all the rows.

                Comment


                  #9
                  Hi,

                  ok. in my example, i am asking for row 0 to 75 in my request. The total results that will meet the criteria is 472.

                  So in DSResponse, do i set start row as 0, end row as 75, total row as 472 but only supply real data from 0 to 75? Which mean when doing this
                  return new DSResponse(records)
                  the records only contain 75 rows?

                  Thanks

                  Comment


                    #10
                    Correct. This will enable paging.

                    Then, for performance, you should find a way to avoid fetching all 472 records in your DMI. All the built-in connectors for SQL, Hibernate, etc do this by requesting specific row ranges from the underlying database.

                    Comment


                      #11
                      It works.
                      Thank you very much for your help :)

                      Comment


                        #12
                        What I am uncertain about is what to return for total rows on subsequent paged fetch requests?

                        Lets say I have 250 rows and my request size is 100. In my custom datasource the first fetch via DMI requests startRow=0 and endRow=100 and since I can detect this is the 1st fetch I do a count and return back startRow=0, endRow=100, totalRows=250. All good.

                        Upon scrolling in the list grid the next request comes in with startRow=100, endRow=200. I fetch the requested 100 rows and return back startRow=100, endRow=200 but what should I set for the value of total rows? I avoid doing a count here since we are paging so I don't know the total rows.

                        How should I be handling this?

                        Thanks

                        Comment


                          #13
                          Return the correct totalRows number. This may indeed involve doing a "count" request against, but you need to do so in case the dataset is modified, otherwise, you could be returning data that doesn't agree in row numbering with previously returned data.

                          Comment

                          Working...
                          X