留言板

SearchContainer with Sorting?

thumbnail
Gnaniyar Zubair,修改在15 年前。

SearchContainer with Sorting?

Liferay Master 帖子: 722 加入日期: 07-12-19 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

Liferay Master 帖子: 722 加入日期: 07-12-19 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

Expert 帖子: 266 加入日期: 08-4-10 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

Liferay Master 帖子: 722 加入日期: 07-12-19 最近的帖子
Thanks kamal.

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


- Gnaniyar Zubair
thumbnail
Ahmed Hasan,修改在14 年前。

RE: SearchContainer with Sorting?

Expert 帖子: 306 加入日期: 07-4-13 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

Liferay Master 帖子: 722 加入日期: 07-12-19 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

Regular Member 帖子: 182 加入日期: 08-6-23 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

Liferay Master 帖子: 722 加入日期: 07-12-19 最近的帖子
Thanks Arun

Can you explain in brief about this?

- Gnaniyar Zubair
thumbnail
zahid khan,修改在14 年前。

RE: SearchContainer with Sorting?

Regular Member 帖子: 116 加入日期: 08-7-30 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

Liferay Master 帖子: 722 加入日期: 07-12-19 最近的帖子
Thanks Zahid

Now it is working fine.


- Gnaniyar Zubair
thumbnail
Gnaniyar Zubair,修改在14 年前。

RE: SearchContainer with Sorting?

Liferay Master 帖子: 722 加入日期: 07-12-19 最近的帖子
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,修改在14 年前。

RE: SearchContainer with Sorting?

New Member 帖子: 7 加入日期: 10-1-4 最近的帖子
which import shall i do to use the BeanComparator
thumbnail
KK rajput,修改在13 年前。

RE: SearchContainer with Sorting?

Expert 帖子: 266 加入日期: 08-4-10 最近的帖子
org.apache.commons.beanutils.BeanComparator
thumbnail
abhinav ladani,修改在13 年前。

sort user based on create date or modified date

New Member 帖子: 4 加入日期: 10-7-29 最近的帖子
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,修改在13 年前。

RE: sort user based on create date or modified date

Expert 帖子: 266 加入日期: 08-4-10 最近的帖子
check this link sorting in search container
Dhana Sekar,修改在13 年前。

RE: SearchContainer with Sorting?

New Member 帖子: 7 加入日期: 11-2-14 最近的帖子
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,修改在13 年前。

RE: SearchContainer with Sorting?

Junior Member 帖子: 86 加入日期: 09-6-26 最近的帖子
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,修改在13 年前。

RE: SearchContainer with Sorting?

Regular Member 帖子: 231 加入日期: 11-3-23 最近的帖子
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,修改在13 年前。

RE: SearchContainer with Sorting?

Junior Member 帖子: 86 加入日期: 09-6-26 最近的帖子
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,修改在13 年前。

RE: SearchContainer with Sorting?

Liferay Master 帖子: 658 加入日期: 10-6-15 最近的帖子
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,修改在10 年前。

RE: SearchContainer with Sorting?

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
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,修改在10 年前。

RE: SearchContainer with Sorting?

Regular Member 帖子: 231 加入日期: 11-3-23 最近的帖子
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(-)