0

I have a celltable in GWT and want to implement sorting functionality on it , from database(Criteria) for that i just want to know how to get the value of the column which has been clicked for sorting

here is my code

            ctJobs.addColumnSortHandler(new ColumnSortEvent.Handler() {
            public void onColumnSort(ColumnSortEvent event) { 
            event.getColumn();
            event.getColumn().getValue("what do we need to write here ???");

from event.getColumn() , i am getting column in the form of object

com.google.gwt.cell.client.ClickableTextCell@188a12e

I want to know the the column's name / value for that i am trying event.getcolumn().getvalue("??"); but what is the parameter for that, or is there any other way of getting column's name which has been clicked.

Thanks

junaidp
  • 10,801
  • 29
  • 89
  • 137

2 Answers2

4

Are you using a ListDataProvider or an AsyncDataProvider for your cell table?

In case of an AsyncDataProvider the sorting must be done on the server side, so there is no need to add a ColumnSortHandler.

Please see the GWT docs.

To get the name of the column clicked for sorting see this question.

Community
  • 1
  • 1
Ioan Agopian
  • 788
  • 5
  • 9
  • thanks , in this scenario you mentioned it using comparator , but i want to sort it from the SQL side , as below if(sortDirection.equals("asc")){ crit.addOrder(Order.asc(sortField)); } i just want to pass this string sortField when a user click on some column , isnt it possible to get the column name which has been selected? – junaidp Oct 26 '11 at 17:35
  • You're welcome. I've added a link to the answer, that explains how to get the name of the sort column. – Ioan Agopian Oct 26 '11 at 19:13
1

When creating the table columns, set the dataStoreName of the column.

column.setDataStoreName("columnX");

Next, when in the AsyncDataProvider get the sort history of the clicked headers like the following

final AsyncDataProvider<SQLRow> dataProvider = new AsyncDataProvider<SQLRow>(){
    @Override
    protected void onRangeChanged(HasData<SQLRow> display) {
        for (int i=0;i<sortList.size();i++) {
            sortList.get(i).getColumn().getDataStoreName();
        }
    }
}
agelbess
  • 4,249
  • 3
  • 20
  • 21