0

I know that in the handler's compulsory onSort(SortEvent) method, you can retrieve the index of the column that was sorted by clicking on the column label. How can you use this to process and sort the data in that column?

As is, I have one column where each cell contains a String representation of the time of day in hh:mm a format. As is it shows in alphabetical order (10:00 am, 10:00 pm, 11:00 am etc).

public final Table getTable(final ChartsWidget cw) {
    Table table = new Table(dataTableObject, TableView.createTableOptions(dataTableObject));
    table.addSortHandler(new SortHandler() {

        @Override
        public void onSort() {
            if (getDataTable().getColumnLabel(event.getColumn()).contains("Time")) {

              //Do something here
            }

        }
    });
    return table;
}

I have not been able to get any farther than this.

user2387855
  • 314
  • 4
  • 9
  • Is this base GWT? If so you could check here: [sorting a cell table](http://stackoverflow.com/questions/6652182/sorting-a-cell-table-probably-just-something-i-didnt-saw) – Andy King Aug 03 '13 at 00:19
  • no, i don't think it is. Unlike the cell table, the client.visualizations Table is instantiated very differently. As far as I can tell, you do not use a dataProvider because the table cannot be set as a dataDisplay. This is the object i'm working with http://gwt-google-apis.googlecode.com/svn/javadoc/visualization/1.1/com/google/gwt/visualization/client/visualizations/Table.html – user2387855 Aug 06 '13 at 16:57
  • How are you populating the table with data? From the example [here](https://code.google.com/apis/ajax/playground/?type=visualization#sort_event) it appears to me that you sort the data and repopulate the table. But I haven't looked at the `visualizations` API, so I'm sorry that I can't be of any real help! – Andy King Aug 06 '13 at 21:46
  • @Andy King you're right Andy, this seems to be the only real way to do it. Thanks for your help – user2387855 Aug 07 '13 at 19:49

1 Answers1

0

Using Andy King's Approach, came up with this. The dataTable is originally populated in order of the first column's entries.

public final Table getTable() {
    final Table table = new Table(dataTableObject,
            TableView.createTableOptions(dataTableObject));
    SortHandler sortHandler = new SortHandler() {

        @Override
        public void onSort(SortEvent event) {
            if (event.getColumn() == 0) {
                if (dataTableObject.getColumnLabel(event.getColumn()).contains("Time")
                        || dataTableObject.getColumnLabel(event.getColumn()).contains(
                                "Frequency")) {
                    reverseRowOrder(); //reverses the order of the rows in dataTableObject
                    table.draw(dataTableObject, TableView.createTableOptions(dataTableObject));
                }
            }
        }
    };
    table.addSortHandler(sortHandler);
    return table;
}
user2387855
  • 314
  • 4
  • 9