2

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.

ses
  • 13,174
  • 31
  • 123
  • 226

2 Answers2

2

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.

Community
  • 1
  • 1
Ioan Agopian
  • 788
  • 5
  • 9
  • thx for that!. but the question still is not answered (see my addition fix in the question). – ses Sep 30 '11 at 15:35
  • Once you get the column from the sortList, you can call table.getColumnIndex(sortColumn) to get the table index of the column. You can also keep a HashMap with the column as key and additional needed data as values.It's all in the link provided. – Ioan Agopian Sep 30 '11 at 15:37
  • ok. thx. i did not recognize the link you provided, it's not enough blue, i guess. – ses Sep 30 '11 at 15:42
0
ColumnSortList sortList = dataTable.getColumnSortList();
Column<?, ?> column = sortList.get(0).getColumn();

Above will give you the required column.

AM01
  • 302
  • 3
  • 18