From the existing t:dataTable code, wrap the column header with t:commandSortHeader and add two more properties, sortColumn and sortAscending, into t:dataTable, just like the code shown below.
Add two member variable into the backing bean and implement Comparable interface just like this:
Here are some notes on the usage:
- sortColumn property in t:dataTable indicate which column name that triggered the sort. The column name is reference from the columnName property of t:commandSortHeader.
- sortAscending property in t:dataTable indicate the particular column sort in ascending/descending order.
- The JAVA class, theBean, must implement Comparable interface in order to provide the sorting facility.
- In the sample code above, I only have one column to sort, thus the compare function only implement one sort. If there is more than one sort, simply expand the if-else statement.