|
Single and multi column sorting |
Top Previous Next |
SortTableModel is capable of using more than one columns to sort the data of a table. You can choose between single and multi-column sorting with the method:
public void setSortMode(int mode);
The int variable SortTableModel.SINGLE_SORT is for single-column, while SortTableModel.MULTI_SORT for multi-column sorting.
You can sort the rows of a table by clicking on a column header. The first time you click on a previously unsorted column, rows are sorted in ascending order. If you click again the data are sorted in descending order. A third click will result in the rows being sorted in ascending order again. In order to remove a sorting from a column, you should have the ALT key pressed while clicking. In MULTI_SORT mode, you can add sorting columns by having the CTRL key pressed while clicking on a column.
You can also use the method:
public void sort(int column, int mode);
to perform sorting programmatically. The first argument is the column to sort, while the second, the sorting mode, which can be:
ADD_SORT: clears sorting columns before adding a column to sort,
REMOVE_SORT: removes a column from sorting and
INSERT_SORT: adds a sorting column.