Foren

how to implement sorting by clicking on header in Search Container

thumbnail
Rewati Raman, geändert vor 11 Jahren.

how to implement sorting by clicking on header in Search Container

Junior Member Beiträge: 97 Beitrittsdatum: 24.02.12 Neueste Beiträge
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
Amit Doshi, geändert vor 11 Jahren.

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

Liferay Master Beiträge: 550 Beitrittsdatum: 29.12.10 Neueste Beiträge
Hi Rewati,

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

Please check thislink.

Regards,
Amit Doshi
thumbnail
Rewati Raman, geändert vor 11 Jahren.

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

Junior Member Beiträge: 97 Beitrittsdatum: 24.02.12 Neueste Beiträge
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
Enrique Valdes Lacasa, geändert vor 9 Jahren.

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

Junior Member Beiträge: 92 Beitrittsdatum: 29.07.14 Neueste Beiträge
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
Priyanka Dhingra, geändert vor 11 Jahren.

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

Liferay Master Beiträge: 501 Beitrittsdatum: 20.12.11 Neueste Beiträge
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