Orderable Search Container in Liferay

Look in to this blog post (sort-search-container-result) if you don't want to use comparator for sorting search container results.

Here is the example how you can make your search container orderable using comparators.
As you click on any of the cloumn of search container result will be sorted this one is the easy way of sorting . To make your search container you need to create custom comparator for each and every cloumn so when ever you click on that column apprpriate comparator for that cloumn will be called and result will be sorted according to that.




Below is the code that you need to copy and paste in your JSP this code will identify which user clicked on which column and on also identify the sorting type like either in dec or asc.



Below is the code for search container.


By using above code you can create a search container. To make your search container orderable you need to set few of the properties as described in code.


If you look into the above code we are fetching first list of all user from database which will return list. So when ever user clicks on any of the column of search container name of that column is stored into the preferences (orderByCol and orderByType) so we can easily identify based on which column we need to do sorting. Once we get that column we need to call appropriate comprator for the same. So if you can look into the above code we are passing those sortByCol and sortType to the one utility class called CustomComparatorUtil so based on parameter passed method of this class will identify which comparator to call.


Below is custom comparator implemented for column



Next PostNewer Post Previous PostOlder Post Home