Client side sorting in a celltable with ListDataProvider & ListHandler

290 views
Skip to first unread message

stuckagain

unread,
Jul 29, 2013, 3:36:40 PM7/29/13
to google-web-tool...@googlegroups.com
Hi,

I tried to discuss this in the GWT google groups, but I did not get any feedback there. I figured since this was a strange design choice in GWT that I should discuss it here:

I just lost 2 hours on getting client side sorting to work correctly in my DataGrid backed by a ListDataProvider. I was using the ColumnSortEvent$ListHandler class that was mentioned in the documentation to handle the client-side sorting.
 
I was calling setList( rows ) on the DataProvider to update the table. When you call setList, the DataGrid is being updated correctly. But clicking on a column to sort (client side) does not work, nothing is being sorted.

I did some investigation an the problem is actually very simple. The The ColumnSortEvent$ListHandler class takes a List as argument instead of the ListDataProvider. When you call setList() on the DataProvider a new wrapper is created and so the ListHandler is looking at the wrong one (the empty list in my case hence no sort effect at all).
 
Wouldn't it be better that the ListHandler would keep a reference to the ListDataProvider instead of using the List ? Then it can call getList() on it when a sort is needed.
 
It is now a bit asymetric: calling setList() updates the table rows, but the sorter does not know... I am sure many many people fall in this trap!
At least the documentation should maybe point this out. I just replaced the ListHandler with my own that just calls getList() on the ListDataProvider everytime a sort is needed, that works completely transparently. I don't want to create and reconfigure a ListHandler every time I update the table data. 

calling clear() and addAll() is an alternative, but it is awkward and should at least be documented.

David

Thomas Broyer

unread,
Jul 29, 2013, 5:39:00 PM7/29/13
to google-web-tool...@googlegroups.com
See (in no particular order):
What change to the documentation would you propose? Made it clear(er) that getList will return a new object after setList is called?

And as one of the above-linked issues points out, an alternative to clearn/addAll is to setList on the ListHandler (using the getList of the ListDataProvider) each time you setList on the ListDataProvider.
Reply all
Reply to author
Forward
0 new messages