Set a table column to sort descending first

Hello, I have not been able to find how to do the following:

A table is sorted initially by column “A”. Column “B” is sortable, but it needs to sort descending first, and toggle to ascending if the column header is clicked again (instead of ascending first, and descending second).

We want this behavior for most date columns in our tables.

I’ve come up with a workaround where I reverse the comparator used for the dates. This works, except that the direction the arrow points in the column heading is opposite of what the user expects.

I would like to be able to do something like this:

table.setColumnDefaultSortAscending(false);

or

table.setColumnDefaultSort(SortOrder.DESC);

Is there a way to do this? Any ideas welcome.

  • Darren Evenson

One not so clean way to do this would be to override Table.sort() and call setSortAscending() before calling the superclass method if that column was clicked.

The problem is that this would require you to keep track of which property was used for sorting prior to the current call, and not flip the sort order automatically if the sort column does not change.