掲示板

how to implement sorting by clicking on header in Search Container

thumbnail
11年前 に Rewati Raman によって更新されました。

how to implement sorting by clicking on header in Search Container

Junior Member 投稿: 97 参加年月日: 12/02/24 最新の投稿
I am fetching the data from database and displaying on the jsp page
and i am able to do so but now i want to sort the table by clicking on the header
how could i do that
need some help on that....

Thanks in Advance..
thumbnail
11年前 に Amit Doshi によって更新されました。

RE: how to implement sorting by clicking on header in Search Container

Liferay Master 投稿: 550 参加年月日: 10/12/29 最新の投稿
Hi Rewati,

It is very well explained in one of the blog along with the example.

Please check thislink.

Regards,
Amit Doshi
thumbnail
11年前 に Rewati Raman によって更新されました。

RE: how to implement sorting by clicking on header in Search Container

Junior Member 投稿: 97 参加年月日: 12/02/24 最新の投稿
Amit Doshi:
Hi Rewati,

It is very well explained in one of the blog along with the example.

Please check thislink.

Regards,
Amit Doshi

thanks Amit

it was very good solution
your suggestion always works..

regards
Rewati Raman
thumbnail
9年前 に Enrique Valdes Lacasa によって更新されました。

RE: how to implement sorting by clicking on header in Search Container

Junior Member 投稿: 92 参加年月日: 14/07/29 最新の投稿
The article that Amit Doshi shared really helped me; I recommend it. Thank you Amit. For those who follow the article, pay attention to a couple of details though. I believe there are only two mistakes in the article that need correction:

1) In the first <liferay-ui:search-container-column-text> tag, it is missing the orderableProperty="firstName" attribute. If you ran into an exception like: "jodd.bean.BeanException: Simple property not found: ... Invalid property:", this could be the reason (it was for me).

2) In the CustomComparatorUtil class, make sure that the orderByCol.equalsIgnoreCase("First Name") is instead:
orderByCol.equalsIgnoreCase("firstName") (and do the same for the rest of orderable properties). If you don't change this, the search container might display, but you won't be able to use the sorting.
thumbnail
11年前 に Priyanka Dhingra によって更新されました。

RE: how to implement sorting by clicking on header in Search Container

Liferay Master 投稿: 501 参加年月日: 11/12/20 最新の投稿
Hi,
For each column create one class that extends OrderByComparator
then override compare method
 @Override
    public int compare(Object obj1, Object obj2)
    {}

and one constructor to fetch the boolean ascending order as a parameter e.g if name is your column

 public NameComparator(boolean asc)
    {
        this.asc = asc;
    }


create a class to compare the values

use "com.liferay.portal.kernel.util.OrderByComparator"
 if (orderByType.equals("asc"))
        {
            orderByAsc = true;
        }
 if (orderByCol.equals("name"))
        {
            orderByComparator = new NameComparator(orderByAsc);
        } 


in your jsp

<liferay-ui:search-container-results>
			&lt;%
				ComparatorUtil.sortList(request, assetList, searchContainer);
				results = ListUtil.subList(assetList, searchContainer.getStart(), searchContainer.getEnd());
				total = assetList.size();
				pageContext.setAttribute("beginIndex",searchContainer.getStart());
				pageContext.setAttribute("endIndex",searchContainer.getEnd());
				pageContext.setAttribute("results", results);
				pageContext.setAttribute("total", total);
			%&gt;
</liferay-ui:search-container-results>


Hope this will help