2
votes

Writing GWT application.

I have CellTable and a code that i'v got from google-example code-site.

I need to implement server-side sorting by clicking on table's columns.

My code for that is:

AsyncDataProvider<MYOBJECT> dataProvider = new AsyncDataProvider<MYOBJECT>() {
 @Override
 protected void onRangeChanged(HasData<MYOBJECT> display) {
   final Range range = display.getVisibleRange();

   ...
   int sortingColumnIndex = 0;
   boolean isAscending = sortList.get(sortingColumnIndex).isAscending();

   // some server-side call here
 }

So, how can I know which column an user clicks on ? I.e. Real index of column of header of column or anything for identifying that column user clicked?

I have only HasData display as an event, but it seems is not enough to determinate the column.

2

2 Answers

2
votes

Sorting a CellTable server-side

The magic number 0, is the index of the sort column in the sort list, and not the column index from the cell table. So sortList.get(0).getColumn() gets you the column that the user clicked on. You have to worry about the other columns in the sortList only if you plan to implement sorting on multiple columns.

0
votes
ColumnSortList sortList = dataTable.getColumnSortList();
Column<?, ?> column = sortList.get(0).getColumn();

Above will give you the required column.