2
votes

I am implementing a GWT CellTable with paging and sorting by multiple columns dynamically. The basics can be found in the CellTable Developer's Guide.

However, the dynamic example does not tell how to find out by which column the user wants to sort (it simply sorts by the 'name' column). That's not enough in my case, as I want to allow the user to sort by different columns.

The only solution I could think of, which is not very elegant, is to keep track of which column is sorted in ascending order or not (using table.getColumnSortList(indexOfColumn).isAscending()) and then figuring out which one has been clicked by comparing the values for each column (the one that changed is probably what the user clicked).

This involves keeping information in my classes that should be available somewhere in the CellTable! But I can't find that information!

Thanks for any help.

1

1 Answers

3
votes

I found the answer. As explained in the javadocs for com.google.gwt.user.cellview.client.ColumnSortList:

An ordered list containing the sort history of Columns in a table. The 0th item is the ColumnSortInfo of the most recently sorted column.

So, to know which column was last sorted by, you simply do:

ColumnSortInfo info = table.getColumnSortList().get(0);
Column<Type> sortByColumn = info.getColumn();