views:

1160

answers:

1

Can someone please explain to me how paging works in SmartGWT?

I see it working in the showcase, but I just can't find it documented anywhere. (The information in the javadocs far from sufficient to understand what's going on.)

I have a ListGrid, and a custom DataSource that interacts with my server.

Let's say I want to set a page size of 25 records in the ListGrid.

What do I have to do:

  • in the ListGrid?
  • in my custom DataSource (has access to DSRequest and DSResponse objects)?
  • in my server?

What are the parameters sent by the SmartGWT client to the server, and what are the parameters the SmartGWT client expects in return?

+1  A: 

If you're using Smart GWT LGPL :

Please read the Javadocs of RestDataSource as it explains this in detail : http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/data/RestDataSource.html

Also have a look at the RestDataSource sample : http://www.smartclient.com/smartgwt/showcase/#featured_restfulds

If you're using Smart GWT EE, then 1) If you're using the SQL connector then you have 0 code to write on the server as the Smart GWT server side code take care of wiring databinding with your database table. 2) If you need mode control over server databinding you can have your own server API's be called when scrolling (fetch), or insert / update / delete occurs. Have a look at the source of this sample : http://www.smartclient.com/smartgwtee/showcase/#javabeans

Click on the View Source button and examine the source for the SupplyItemDMI class. Notice how you can obtain the start row, end row parameters of the request.

// By default, for a DSRequest of type "fetch", a method named "fetch" is invoked.  
// You can customize this via the <serverObject> declaration.  
public DSResponse fetch(DSRequest dsRequest)  
    throws Exception {  
   log.info("procesing DMI fetch operation");  

    // Fetch a List of matching SupplyItem Beans from some pre-existing Java object model  
    // provided by you, represented by "SupplyItemStore" in this example  
    List matchingItems =  
        SupplyItemStore.findMatchingItems((Long) dsRequest.getFieldValue("itemID"),  
                (String) dsRequest.getFieldValue("itemName"));  

    // this implementation shows data paging (returning only ranges of requested records)  
    long startRow = dsRequest.getStartRow();  
    long endRow = dsRequest.getEndRow();  

    long totalRows = matchingItems.size();  
    DSResponse dsResponse = new DSResponse();  
    dsResponse.setTotalRows(totalRows);  
    dsResponse.setStartRow(startRow);  

    endRow = Math.min(endRow, totalRows);  
    dsResponse.setEndRow(endRow);  

    // trim the data to the requested range of records.  In a real application, the startRow  
    // and endRow would be passed to the ORM layer or to SQL for maximum efficiency.  
    List results;  
    if (totalRows > 0) {  
        results = matchingItems.subList((int) dsResponse.getStartRow(),  
                (int) dsResponse.getEndRow());  
    } else {  
        results = matchingItems;  
    }  

    // just return the List of matching beans  
    dsResponse.setData(results);  

    return dsResponse;  
}
Sanjiv Jivan