This might help you,

this is how I do it, using Jens' suggestion with setDataStoreName() on the 
columns.  This example is for sorting invoices, although I do the sorting 
client side to reduce server requests

        ArrayList<Invoice> dataInRange = 
appData.getInvoiceCacheBetweenDates(startBox.getValue(), endBox.getValue());
        final ColumnSortList sortList = cellDataGrid.getColumnSortList();
        if(sortList.size() > 0) {
        
            final ColumnSortInfo sortInfo = sortList.get(0);
            final String dataStoreName = 
sortInfo.getColumn().getDataStoreName();
            
            Collections.sort(dataInRange, new Comparator<Invoice>() {
                
                public int compare(Invoice o1, Invoice o2) {
                  
                    if (o1 == o2) {
                        return 0;
                    }
                    
                    
                    // Compare the name columns.
                    int diff = -1;
                    
                    if(o1 == null) {
                        
                    } else if(dataStoreName.equals("ref")) {
                        diff = (o2 != null) ? 
("INV"+o1.getRef()).compareTo("INV"+o2.getRef()) : 1;
                    } else if(dataStoreName.equals("amount")) {
                        Double amount1 = new Double(o1.getAmount());
                        Double amount2 = new Double(o2.getAmount());
                        diff = (amount2 != null) ? 
amount1.compareTo(amount2) : 1;
                    } else if(dataStoreName.equals("employer")) {
                        Employer employer1 = 
appData.getEmployersCache().get(o1.getEmployerId());
                        Employer employer2 = 
appData.getEmployersCache().get(o2.getEmployerId());
                        diff = (employer2 != null) ? 
(employer1.getEmployerName()).compareTo(employer2.getEmployerName()) : 1;
                    } else if(dataStoreName.equals("raised")) {
                        diff = (o2 != null) ? 
o1.getRaisedDate().compareTo(o2.getRaisedDate()) : 1;
                    } else if(dataStoreName.equals("paid")) {
                        diff = (o2 != null) ? 
o1.getPaidDate().compareTo(o2.getPaidDate()) : 1;
                    } else if(dataStoreName.equals("status")) {
                        diff = (o2 != null) ? 
(o1.getInvoiceStatus().getListItem()).compareTo(o2.getInvoiceStatus().getListItem())
 
: 1;
                    }

                    return sortInfo.isAscending() ? diff : -diff;
                }
            });
            
            
        }
        
        updateRowData(0, dataInRange);
        updateRowCount(dataInRange.size(), true);


On Friday, June 14, 2013 3:21:51 PM UTC+1, Jens wrote:
>
> You can set a string identifier to your columns by using 
> Column.setDataStoreName(). The easiest identifier would be the raw database 
> column name. Then you can go through the ColumnSortList of your CellTable, 
> read the database column name and sort order of each sorted column and pass 
> this information to the server. This information can then be used to build 
> your ORDER BY clause.
>
> Then you only need to detect if sort order has been changed so you can 
> switch back to page one in your CellTable. To do so you can add a 
> ColumnSortHandler to each column, which gets notified as soon as sort order 
> changes.
>
> -- J.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to