0

How can I sot every column of a Celltable in GWT

@Override
    public void addSortableColumn() {
            for (int column = 0; column < cellTable.getColumnCount(); column++) {
                    cellTable.getColumn(column).setSortable(true);
            }
            addSortHandler();
    }

    private void addSortHandler() {
            cellTable.addColumnSortHandler(new ColumnSortEvent.Handler() {
                    public void onColumnSort(ColumnSortEvent event) {
                            List newData = new ArrayList(cellTable.getVisibleItems());
                            if (event.isSortAscending()) {
                                    Collections.sort(newData);
                            } else {
                                    Collections.reverse(newData);
                            }
                            cellTable.setRowData(cellTable.getVisibleRange().getLength(),newData);
                    }
            });
    }

I am using above code for sorting but it is not performing any kind of sorting on any column though the columns are clickable.

This is one of the model I am passing to my celltable which is being generated at run time.

public class MyModel implements Comparable<MyModel>
{
   private String column1;
   private String column2;
   private String column3;
   private String column4;
   private String column5;


        @Override public int compareTo(SearchNewNumberOrderModel o) {
                return this.column1.compareTo(o.column1);
        }
}
Ashish
  • 14,295
  • 21
  • 82
  • 127
  • This answer may be useful: http://stackoverflow.com/a/19262375/1464763 – David Levesque Jan 24 '14 at 17:39
  • You can go directly into gwt project documentation to find out more about sorting cell table here --> http://www.gwtproject.org/doc/latest/DevGuideUiCellTable.html#columnSorting – i-bob Jan 24 '14 at 17:42
  • The problem might be that you bypass gwt-way of how to sort and you try to create your own version of sorting cell-table, so your solution looks good but it does not work because GWT... – i-bob Jan 24 '14 at 17:43
  • so basically you can not write generic version of column sorting. You would have to repeat the same process in every place you wants to perform the sorting right ? – Ashish Jan 24 '14 at 17:59

0 Answers0