Well, I'd start out by trying:
public MySortHandler(List<Book> BOOKS, CellTable myCellTable,
Column columnA, .... you get the picture) {
         thisList = new ArrayList (BOOKS);
         ......
    }

On Feb 23, 9:56 am, Josh K <kendrick.j...@gmail.com> wrote:
> Ok, I got something working using the example you provided, but I
> don't like how I implemented it. It wasn't hard, but everything I've
> wanted to do in GWT so far has been easy, so this seems kind of
> messy..
>
> But, I guess trying to implement sorting using a ListSortHandler would
> have been just as messy since I would have had to setComparator for
> every column still right?
>
> Also, this is probably a stupid Java error, but I'm trying to re-use
> my SortHandler so I broke it into it's own class. In each composite
> I've got a list of what is displayed in the tables, call it BOOKS.
> What I've been trying to do is instantiate the SortHandler:
>
> new MySortHandler (BOOKS, myCellTable, columnA, columnB, columnC,
> etc..)
>
> And in class I've got something like
> public class MySortHandler {
>     private List<Book> thisList;
>
>     public MySortHandler(List<Book> BOOKS, CellTable myCellTable,
> Column columnA, .... you get the picture) {
>          thisList = BOOKS;
>          ......
>     }
>
> Down below I sort thisList, and at the end, I assign it back to BOOKS
> and do cellTable.setRowData(BOOKS);
>
> When I go to sort though, nothing happens. I think I narrowed it down
> to understand for some reason the list isn't getting copied over or
> something like that? If I have MySortHandler as an internal private
> class to my composite and I use the original List BOOKS, it sorts, but
> when I try to do like I was doing above, it doesn't work.
>
> Can anyone explain why, and give me an idea of how to fix it. I'll be
> alright without code, just don't even know how to get around this. I'd
> hate to have to stick an internal SortHandler at the end of each
> composite.
>
> On Feb 14, 12:19 pm, Josh K <kendrick.j...@gmail.com> wrote:
>
> > What I was getting confused about doing it this way though is if I'm
> > allowing the data to be sorted by 4 or 5 different columns, would I
> > have to say something like:
>
> > if (event.isSortAscending && nameColumn) {
> >     Collections.sort(newData, nameAscComparator)} else if (nameColumn) {
>
> >     Collections.sort(newData, nameDescComparator)} else if 
> > (event.isSortAscending && timeRequestedColumn) {
>
> >     Collections.sort(newData, timeRequestedAscComparator)
>
> > } ....
>
> > ya know where I have to have a different asc and desc comparator for
> > each column and figure out which column was selected before I sort?
>
> > I'm thinking that I'll have a small enough set of rows (probably max
> > 100 rows at a time), that if I just make the columns sortable, it will
> > be fine if I don't use paging. So maybe I should do what Greg
> > mentioned and download all the data and use a ListDataProvider. What I
> > liked about the AsyncDataProvider though is that people can change the
> > value of a cell and hit enter and it's updated in the database because
> > this will be an application a couple are using at one time all dealing
> > with the same data so I need changes to show up on what other people
> > are seeing.
>
> > BTW, thanks a lot guys!
>
> > On Feb 14, 10:00 am, John LaBanca <jlaba...@google.com> wrote:
>
> > > If you are supporting paging, then a local sort will only sort the current
> > > page, whereas a database sort would sort the data return the results for 
> > > the
> > > current page.  For example, if you are on the first page and do a reverse
> > > sort, do you want to see all the names that start with z (database sort), 
> > > or
> > > do you want to see all of the names that start with a in reverse order
> > > (local sort of the current page).
>
> > > That being said, you can cache the values locally in a list and use
> > > ListSortHandler.  Alternatively, you can add a ColumnSortEvent.Handler to
> > > CellTable and copy and sort the return of CellTable#getVisibleItems().  
> > > The
> > > code would be something like the following:
>
> > > cellTable.addColumnSortHandler(new ColumnSortEvent.Handler() {
> > >   public void onColumnSort(ColumnSortEvent event) {
> > >     List<T> newData = new ArrayList(cellTable.getVisibleItems()); // Copy
> > > the data
> > >     if (event.isSortAscending) {
> > >       Collections.sort(newData, myAscComparator); // Sort ascending.
> > >     } else {
> > >       Collections.sort(newData, myDescComparator); // Sort descending.
> > >     }
> > >     cellTable.setRowData(cellTable.getVisibleRange(), newData);
> > >   }
>
> > > });
>
> > > Thanks,
> > > John LaBanca
> > > jlaba...@google.com
>
> > > On Mon, Feb 14, 2011 at 12:53 AM, Josh K <kendrick.j...@gmail.com> wrote:
> > > > I've been developing an application in GWT that has data I've been
> > > > displaying in a CellTable. I've set it up with a few TextColumns and a
> > > > few EditTextColumns. I've got it set up to where if someone changes
> > > > the data in an EditText cell, it sends an asynchronous request to the
> > > > database and updates that row in the DB table. In short, I've got all
> > > > this working using AsyncCallbacks and an AsyncDataProvider.
>
> > > > Since 2.2 came out, I want to implement column sorting, kind of like
> > > > is seen in this example:
> > > >http://gwt.google.com/samples/Showcase/Showcase.html#!CwCellTable
> > > > , but with an AsyncDataProvider. I want to sort the columns locally
> > > > because I think it'd be faster than making an Async DB call again each
> > > > time someone clicks to sort (which is the impression of what was
> > > > supposed to happen if I used an AsyncHandler.
>
> > > > So I THINK what I'm looking for is some way to use a ListHandler with
> > > > an AsyncDataProvider?
>
> > > > Can anyone shed some light on this? Maybe done it before or know the
> > > > direction I'm supposed to? If it's even do-able?
>
> > > > --
> > > > You received this message because you are subscribed to the Google 
> > > > Groups
> > > > "Google Web Toolkit" group.
> > > > To post to this group, send email to 
> > > > google-web-toolkit@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > google-web-toolkit+unsubscr...@googlegroups.com.
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/google-web-toolkit?hl=en.

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

Reply via email to