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);
}
}