I have a Table
and TableViewer
that are set up to take a ViewerComparator
:
this.viewer.setComparator( this.comparator );
Now I am looking at my table. I click on a column header. The table sorts on that row. I click on that column header again and it sorts in the other direction. I click on a different column header and the sorting switches to the new column. This works beautifully.
My question is if there is a way to remove the sorting. This would mean getting rid of the sort arrow on top of the column header that I clicked, the gray background on the sorted column's elements would disappear, and the data would go back into its original order. I am open to adding some sort of button somewhere to start this command.
Is this possible?
The Table
s sort indicator and the comparator used by the TableViewer
are actually independent.
To remove the sort indicator, call table.setSortDirection( SWT.NONE )
. To remove the comparator, call viewer.setComparator( null )
.
You could let the user switch through UP
, DOWN
, NONE
when the column header is selected or provide an extra UI element to reset the sorting.