final TextColumn<PersonProxy> lastNameColumn = new
TextColumn<PersonProxy>() {
      @Override
      public String getValue(PersonProxy contact) {
        return contact.getLastName();
      }
    };
lastNameColumn.setSortable(true);
cellTable.addColumn(lastNameColumn,"Last Name");

AsyncDataProvider<PersonProxy> provider = new
AsyncDataProvider<PersonProxy>() {
@Override
protected void onRangeChanged(final HasData<PersonProxy> display) {


       final Range range = display.getVisibleRange();
   final PersonRequest r2 = requestFactory.personRequest();
       final ColumnSortList sortList = cellTable.getColumnSortList();
       final List<SortConfigProxy> sorts = new ArrayList<SortConfigProxy>();
       for(int i=0; i< sortList.size();i++){

               if(sortList.get(i).getColumn().equals(lastNameColumn)){
         SortConfigProxy p = r2.create(SortConfigProxy.class);
         p.setColumn("lastName");
         p.setOrder(sortList.get(i).isAscending() ? "asc" : "desc");
         sorts.add(p);
         }
        }

        
r2.getAllPersons(sorts,range.getStart(),range.getLength()).with("pet").fire(new
Receiver<List<PersonProxy>>(){
 @Override
            public void onSuccess(List<PersonProxy> response) {
updateRowData(range.getStart(), response);
            }
});

}

@Override
public void addDataDisplay(HasData<PersonProxy> display) {
 super.addDataDisplay(display);
     requestFactory.personRequest().countPersons().fire(new
Receiver<Long>(){
      public void onSuccess(Long response) {
              updateRowCount(response.intValue(), true);
            }
      });
}
};
provider.addDataDisplay(cellTable);

SortConfigProxy  is a ValueProxy that send to the server side the sort
column information.

On the server side.

public List<Person> getAllPersons(List<SortConfig> sortConfig,int start,int
end){
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
Criteria cri =
session.createCriteria(Person.class).setFirstResult(start).setMaxResults(end);
if(sortConfig.size()>0){
System.out.println("order ->> "+sortConfig);
for(SortConfig sort:sortConfig){
if(sort.getOrder().equals("asc"))
cri.addOrder(Order.asc(sort.getColumn()));
else
cri.addOrder(Order.desc(sort.getColumn()));
}
}

@SuppressWarnings("unchecked")
List<Person> persons = cri.list();
tx.commit();
return persons;
} catch (RuntimeException e) {
if (tx != null)
tx.rollback();
throw e;
} finally {
session.close();
}
}

Example with Hibernate.

good luck

2012/2/21 kapricanon <[email protected]>

> Hi
>
> I am using the sample code example for ListDataProvider column sorting
>
> (http://code.google.com/webtoolkit/doc/latest/
> DevGuideUiCellTable.html#columnSorting)
>
>  to sort on a column in my application. Debugging the application I
> can see the column is being sorted after I click on column header but
> the display is never refreshed in the view.
>
> Things to note is I am using paging for displaying my data as the data
> can be quite huge.
>
> Thanks
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>


-- 
ISC. Daniel Mauricio Patiño León.
Director ejecutivo
Liondev S.A. de C.V.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to