GWT CellTable columnsorting
Asked Answered
O

2

2

I am trying to sort on a column in GWT using their ListDataProvider Sorting example as a reference

http://code.google.com/webtoolkit/doc/latest/DevGuideUiCellTable.html#columnSorting

The problem is I can see my table column data is getting sorted (by using the debugger) but the table never gets refreshed. Looking at the example in the above link they do not explicitly refresh the display. Am I missing something here?

Thanks.

Ovenware answered 21/2, 2012 at 15:28 Comment(0)
U
7

My experience says sort handler (i.e. ListHandler) is sensitive to the List, which ListDataProvider has, when you are creating it.

So I recommend not to delete or set new List for ListDataProvider (of course I think it should has at least an empty (not null) list when you are creating).

Just use ListDataProvider.getList() and do your jobs on it.

For example for removing all current rows and setting new data, just call ListDataProvider.getList().clear() and then ListDataProvider.getList().addAll(yourNewData); do not call setList() or the sorting becomes not working.

Unsatisfactory answered 26/2, 2012 at 17:50 Comment(1)
Hamzeh, you are a rockstar! You don't know how long I have been searching for a solution for this. Using getList().addAll() instead of setList() did the trick for me.Gosser
B
3

Those two examples are useless and confusing.

Using ListHandlers and DataProviders are also not too helpful when illustrating how to use Cell/Grid tables.

The examples obfuscate and hide one simple characteristic of GWT Cell/Grid tables - you merely need to replace and feed the list into the table every time the data change in anyway.

The examples' use of ListHandlers, Async handlers and DataProviders complicates a rather simple process by throwing in a whole bunch of fluffy unhelpful abstract elegance. Essentially these abstract and hideous structures themselves push and repush records into the table list. Don't pay attention to use of the Timer.

Might as well take the table list by its bull-horns and do it yourself - much simpler that way. I cannot remember exactly how I do it as I don't have my code with me.

What you need to do is to keep a buffer copy of the list of records. This is the list of records to be displayed in the table.

It does not matter whether you are doing async or otherwise - any change to the data you wish to make is to be made on that buffer copy. Your GWT-RPC should update that buffer.

When the table requests for ascending sort, your comparator/filtrator would produce an ascending copy of your buffered list to replace data in the table using setRowData. Similarly, when the table requests for descending or for specialised filtering.

Using DataProvider is useful if you wish to let it manage paging for you. It is much simpler to handle the GWT-RPC yourself. The DataProvider is supposed to handle the sorting and filtering for you by requesting the server to send it a new list that is sorted/filtered according to the wishes of the table. Why would you want to consume network traffic by letting the server manage your filtering/sorting, unless you have more than 10 pages of records.

So for a simple 50 record experimentation example, manage the buffer list yourself.

Brunt answered 22/2, 2012 at 4:40 Comment(3)
Thanks for your response I totally agree with you on the illustrations not be very helpful, so true... But done exactly what you have said and actually got it working. Thanks again.Ovenware
Someone who has not worked very much with Cell/Grid tables voted me down.Brunt
Async is important if your data is > ≈10K elements (depending on the elements), otherwise you'll slow down your interface potentially. I have datagrid tables that do both.Sherrie

© 2022 - 2024 — McMap. All rights reserved.