Message Boards

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sorting the records
Answer
12/4/11 12:08 PM
Is it possible to have a fixed sorting of the records? Nothing that the user can change by clicking the column header but instead all records get sorted by two columns priority and date, so that all records are sorted by priority but the ones with the same priority are not random but in date order?

RE: Sorting the records
Answer
12/4/11 9:34 PM as a reply to Hiran Chaudhuri.
Hola Hiran,

If nothing is defined (<order> in field ) the view comes out by default ordered by primaryKey. You can add the <order>true</order> in case you want a column "orderable".

In case you have a very special need about ordering fields in the view, you can modify the generated code.

If I had to do something like you need, I would go, by modifying generated portlet "showViewDefault" function. As you will notice, records are stored in a java List (tempResults), and sended in the request object to the JSP. The order here is defined by the comparator.

1            String orderByType = renderRequest.getParameter("orderByType");
2            String orderByCol  = renderRequest.getParameter("orderByCol");
3            OrderByComparator comparator = PersonNamesComparator.getPersonNamesOrderByComparator(orderByCol,orderByType);
4            MultiVMPoolUtil.clear();
5
6            tempResults = PersonNamesLocalServiceUtil.findAllInGroup(groupId, comparator);


You can change the comparator (see xxxxxComparator.java), or maybe you can change ".findAllInGroup(......" for a ".dynamicQuery(....."

For more info in Dynamic Query, see some examples here :

http://www.liferay.com/es/community/wiki/-/wiki/Main/Queries+2%3A+DynamicQuery+API

Was this of any help?

Saludos, Jack.

RE: Sorting the records
Answer
12/6/11 9:37 AM as a reply to Jack A. Rider.
Jack A. Rider:
If nothing is defined (<order> in field ) the view comes out by default ordered by primaryKey. You can add the <order>true</order> in case you want a column "orderable".
In case you have a very special need about ordering fields in the view, you can modify the generated code.

Very special?
Ok, maybe I need to rephrase my question:

Is there a possibility to define how the xmlportletfactory will create service.xml, especially the <order> element?
This snipped is taken from liferay-portal-src-6.0.5\definitions\liferay-service-builder_6_0_0.dtd:
1
2<!--
3The order element specifies a default ordering and sorting of the entities when
4they are retrieved from the database.
5-->
6<!ELEMENT order (order-column+)>


Jack A. Rider:

If I had to do something like you need, I would go, by modifying generated portlet "showViewDefault" function. As you will notice, records are stored in a java List (tempResults), and sended in the request object to the JSP. The order here is defined by the comparator.

Yes, this is what needs to be done ultimately. I'm just trying to understand how much I can get automatically generated and when I take over coding again.

Jack A. Rider:
Was this of any help?

Definitely. From what I saw so far this generation attempt will save me quite some tedious work, however I want to understand how it works so I get most out of it. :-)