Fórum

SearchContainer with Sorting?

thumbnail
Gnaniyar Zubair, modificado 14 Anos atrás.

SearchContainer with Sorting?

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Hi all,


I am using SearchContainer in Liferay-5.2.2. i want to use sorting with ascending and descending order.

Can i use SearchContainer with Sorting ?


Thanks in advance

- Gnaniyar Zubair
thumbnail
Gnaniyar Zubair, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Hi all,

how to sort my search container list like Liferay user list in control panel?

In Liferay Users Portlet from Control Panel,There is a option for Ascending / descending the firstname , last name.

i want to do like that .

any idea?


- Gnaniyar Zubair
thumbnail
kamalkant rajput, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Expert Postagens: 266 Data de Entrada: 10/04/08 Postagens Recentes
Gnaniyar Zubair:
Hi all,

how to sort my search container list like Liferay user list in control panel?

In Liferay Users Portlet from Control Panel,There is a option for Ascending / descending the firstname , last name.

i want to do like that .

any idea?


- Gnaniyar Zubair

Hi Gnaniyar,
How r u? In liferay 5.2.2 search container is implemented as tag library under liferay-ui. It is having an attribute orderByCol.
use that.

HTH
thumbnail
Gnaniyar Zubair, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Thanks kamal.

I will try it out and let u know if any.


- Gnaniyar Zubair
thumbnail
Ahmed Hasan, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Expert Postagens: 306 Data de Entrada: 13/04/07 Postagens Recentes
Thanks folks for the response.

For advanced sorting, you can also use, BeanComparator (from apache commons, which is available in LR by default. )

Just see the following code snippet.

BeanComparator comp = new BeanComparator("col-name");
Collections.sort(list, comp);

Where col-name is the name of the column on which you want to sort a list.

By default the sorting is in the ascending order. If you want to reverse the order, just use,

Collections.reverse(list);

For any help feel free to contact me,

Ahmed Hasan
CTO, TransIT mPower Labs (P) Ltd.
info@mpowerglobal.com
mPower Global Inc.
A Liferay expert company.
thumbnail
Gnaniyar Zubair, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Thanks for your response.

we can use this BeanComparator for Common list object.

But, Can we apply the same for Search Container also?

Thanks in advance.

- Gnaniyar Zubair
Arun Kumar S, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Regular Member Postagens: 182 Data de Entrada: 23/06/08 Postagens Recentes
Gnaniyar Zubair:
Thanks for your response.

we can use this BeanComparator for Common list object.

But, Can we apply the same for Search Container also?

Thanks in advance.

- Gnaniyar Zubair



Hi Gnaniyar ,

Yes you can apply BeanComparator for Search Container also . I have tested its working fine .


Thanks
thumbnail
Gnaniyar Zubair, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Thanks Arun

Can you explain in brief about this?

- Gnaniyar Zubair
thumbnail
zahid khan, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Regular Member Postagens: 116 Data de Entrada: 30/07/08 Postagens Recentes
Use the following code snippets to get Sorting in SearchContainer.

In your list page add these lines.

String clientName = "Client Name"+"<div>"+ " <img name='clientasc' src='/html/themes/classic/images/arrows/01_up.png'"+" onclick='sort(this.name);'>"
+ " <img name='clientdesc' src='/html/themes/classic/images/arrows/01_down.png'"+" onclick='sort(this.name);'>"+"</div>";

String email = "Email"+"<div>"+ " <img name='emailasc' src='/html/themes/classic/images/arrows/01_up.png'"+" onclick='sort(this.name);'>"
+ " <img name='emaildesc' src='/html/themes/classic/images/arrows/01_down.png'"+" onclick='sort(this.name);'>"+"</div>";

String [] headersList = {"Client ID",clientName,email,"Phone","Edit"};



In your portlet.jsp add this javascript function


function sort(sortName) {
var url = "<portlet:renderURL windowState="<%= LiferayWindowState.EXCLUSIVE.toString() %>">
<portlet:param name="struts_action" value="/portal/portlet/view" />
</portlet:renderURL>&sortName="+sortName;


jQuery('#PORTLET').load(url);
}


aND IN UR ACTION FILE have this lines code.




String sortName = ParamUtil.getString(renderRequest, "sortName");
_log.info("sortName=>>"+sortName);
if(Validator.isNotNull(sortName) && sortName.equalsIgnoreCase("clientasc")){
BeanComparator comp = new BeanComparator("clientName");
Collections.sort(clientList, comp);
}
else if(Validator.isNotNull(sortName) && sortName.equalsIgnoreCase("clientdesc")){
BeanComparator comp = new BeanComparator("clientName");
Collections.sort(clientList, comp);
Collections.reverse(clientList);
}
else if(Validator.isNotNull(sortName) && sortName.equalsIgnoreCase("emailasc")){
BeanComparator comp = new BeanComparator("email");
Collections.sort(clientList, comp);
}
else if(Validator.isNotNull(sortName) && sortName.equalsIgnoreCase("emaildesc")){
BeanComparator comp = new BeanComparator("email");
Collections.sort(clientList, comp);
Collections.reverse(clientList);
}
renderRequest.setAttribute("CLIENTLIST", clientList);


HTH

Zahid Khan
thumbnail
Gnaniyar Zubair, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Thanks Zahid

Now it is working fine.


- Gnaniyar Zubair
thumbnail
Gnaniyar Zubair, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

Liferay Master Postagens: 722 Data de Entrada: 19/12/07 Postagens Recentes
Sorting is working fine with BeanComparator. Thank you Hasan Bhai for sharing your knowledge.

I have a doubt on this. I have 2 Entity. (Entity-1 & Entity-2) . Entity-1 has userId, Entity-2 has userName.

if i sort Entity-1's userId, it should sort based on userName not userId.
( Now it is sorting based on userId like 001,002,003,004 but i want to sort through userName like Abdul, Balu, Christoper, David,...etc )

how to do this?

your swift response shall be most helpful.

Thanks in advance.

- Gnaniyar Zubair
thumbnail
amira princesse, modificado 14 Anos atrás.

RE: SearchContainer with Sorting?

New Member Postagens: 7 Data de Entrada: 04/01/10 Postagens Recentes
which import shall i do to use the BeanComparator
thumbnail
KK rajput, modificado 13 Anos atrás.

RE: SearchContainer with Sorting?

Expert Postagens: 266 Data de Entrada: 10/04/08 Postagens Recentes
org.apache.commons.beanutils.BeanComparator
thumbnail
abhinav ladani, modificado 13 Anos atrás.

sort user based on create date or modified date

New Member Postagens: 4 Data de Entrada: 29/07/10 Postagens Recentes
Hello Zubair Sir,


I am just new in liferay .i have been just completed my study and join as company as an employee .


I want to sort the Users By createDate,modifiedDate like directory portlet.

but i never found any comparater method in liferay source.


2)
how can i extend Wol portlet or friend Portlet will u please gide me?

Liferay search Conteiner column text tag is not in working i think liferay have no comparator method for date sortin thats why am i right sir.
thumbnail
KK rajput, modificado 13 Anos atrás.

RE: sort user based on create date or modified date

Expert Postagens: 266 Data de Entrada: 10/04/08 Postagens Recentes
check this link sorting in search container
Dhana Sekar, modificado 13 Anos atrás.

RE: SearchContainer with Sorting?

New Member Postagens: 7 Data de Entrada: 14/02/11 Postagens Recentes
Thanks for your information,
can you send any sample code for writing bean comparator and how to use that bean comparator in our jsp?


Thanks,
Dhanasekar.S
thumbnail
Luis Rodríguez Fernández, modificado 13 Anos atrás.

RE: SearchContainer with Sorting?

Junior Member Postagens: 86 Data de Entrada: 26/06/09 Postagens Recentes
Thanks everyboby, very useful thread!!!

Hi Dhana,

For me is working in this way:

1. In my Action class:

//Get the column, atribute of the VO object, for that I want to do the ordering
String orderByCol = ParamUtil.getString(request, "orderByCol");
		if(orderByCol==null || orderByCol=="")
			orderByCol = "fechaInicio";
		request.setAttribute("orderByCol", orderByCol);

//Create an instance of BeanComparator telling it wich is the order column
BeanComparator beanComparator = new BeanComparator(orderByCol);

//Get the type of ordering, asc or desc
String orderByType = ParamUtil.getString(request, "orderByType");
		if(orderByType==null || orderByType=="")
			orderByType = "desc";
		request.setAttribute("orderByType", orderByType);

//Sort
if(orderByType.equals("desc")){
			Collections.sort(listaTotal, Collections.reverseOrder(beanComparator));
			
		} else {
			Collections.sort(listaTotal, beanComparator);
		}

//Return the orderer list
request.setAttribute("total", listaTotal.size());
		request.setAttribute("listaAux", listaTotal.subList(start,
				resultado.getSolicitudes().size() &lt; start + del ? resultado.getSolicitudes().size()
						: start + del));


2. In my JSP:

&lt;%
	//Get the list and the number of items for displaying
	List listaAux = (List)request.getAttribute("listaAux");
	int numItems= ((Integer)request.getAttribute("total")).intValue();
	
	//Get the order params, column and type (asc or desc)
	String orderByCol =  (String)request.getAttribute("orderByCol");
	String orderByType = (String)request.getAttribute("orderByType");
%&gt;


<!--
Use the <liferay-ui:search-container> tag for displaying the results, using the orderable and orderableProperty params in the columns that I need
-->

<liferay-ui:search-container delta="5" emptyresultsmessage="No hay solicitudes" iteratorurl="<%= renderResponse.createRenderURL() %>" orderbycol="<%= orderByCol %>" orderbytype="<%= orderByType %>">
	
		<liferay-ui:search-container-results results="<%=listaAux%>" total="<%=numItems%>" />						
		<liferay-ui:search-container-row classname="com.vo.SolicitudVO" keyproperty="uuid" modelvar="solicitud">
		
		    	<liferay-ui:search-container-column-text name="Fecha Inicio" property="fechaInicio" orderable="true" orderableProperty="fechaInicio" />

             
		   </liferay-ui:search-container-row>
		
		<liferay-ui:search-iterator paginate="true" />
	
	</liferay-ui:search-container>




Hope it helps,

Luis
venka reddy, modificado 12 Anos atrás.

RE: SearchContainer with Sorting?

Regular Member Postagens: 231 Data de Entrada: 23/03/11 Postagens Recentes
hi Luis,

BeanComparator beanComparator = new BeanComparator(orderByCol);

when i have written BeanComparator as above ,it shows an error cannot find symbol.

Help me out please!!!
thumbnail
Luis Rodríguez Fernández, modificado 12 Anos atrás.

RE: SearchContainer with Sorting?

Junior Member Postagens: 86 Data de Entrada: 26/06/09 Postagens Recentes
Hi Venka,

Do you have in you classpath the commons-beanutils.jar? You can find it here findjar.

Is it a compiler error or is at runtime? For runtime you need to add to your classpath, (WEB-INF/lib of your portlet). For compiling you need to add to your build path (if you are using eclipse just right click over the jar and select "Add to your build path".

Hope it helps,

Luis
thumbnail
Apoorva Prakash, modificado 13 Anos atrás.

RE: SearchContainer with Sorting?

Liferay Master Postagens: 658 Data de Entrada: 15/06/10 Postagens Recentes
Hello all,
If I am getting the things correct, I thinks there is one more easy way to get sorted search container.
<order by="asc">
<order-column name="accessrole" case-sensitive="false" />
</order>

So, after that, we'll get sorted list by all ways. Just pass it to search container.

Hope this will help.

Thanks and regards...
thumbnail
mohammad azaruddin, modificado 10 Anos atrás.

RE: SearchContainer with Sorting?

Expert Postagens: 492 Data de Entrada: 17/09/12 Postagens Recentes
HI all

when i try to sort List <AnnouncementsEntry> annoncementDeliveries=AnnouncementsEntryLocalServiceUtil.getAnnouncementsEntries(-1, -1);
this list i'm getting java.lang.UnsupportedOperationException: Please make a copy of this read-only list before modifying it. error..How to resolve this.

I tried create new ArrayList and add all element to it and sort the new list but still facing same problem


*****i'm not working on search container.i am just trying to sort the list*****
venka reddy, modificado 9 Anos atrás.

RE: SearchContainer with Sorting?

Regular Member Postagens: 231 Data de Entrada: 23/03/11 Postagens Recentes
Hi mohammad azaruddin,


In Liferay we have one utility class ListUtil which can help you to sort out this prob. Have a look into this method ListUtil.copy(-)