掲示板

Dynamic List OrderBy in VM Template?

12年前 に James Burris によって更新されました。

Dynamic List OrderBy in VM Template?

New Member 投稿: 4 参加年月日: 12/03/16 最新の投稿
We've been LR users for a long time and we're trying take advantage of the DDL feature in 6.1. However, we are having a bit of a struggle including the correct "orderby" language in our list template. After having to bump the server a few times to recognize faulty template changes, we're reaching out for an assist. Thanks, in advance.

Simple list template, based on https://gist.github.com/1642366:

#set ($ddlRecordsUtil = $serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService"))
#set ($recordSetId = $getterUtil.getLong($reserved_record_set_id.data))
#set ($records = ${ddlRecordsUtil.getRecords($recordSetId)})
<table class="pp-table"><tr><th>NAME</th><th>FROM YEAR</th><th>TO YEAR</th></tr>
#foreach ($record in $records)
#set ($name = $record.getField("text5549").getValue())
#set ($from-year = $record.getField("text4701").getValue())
#set ($to-year = $record.getField("text5473").getValue())
<tr>
<td><strong>$name</strong></td>
<td>$from-year</td>
<td>$to-year</td>
</tr>
#end
</table>
12年前 に James Burris によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 4 参加年月日: 12/03/16 最新の投稿
Bump...

Any leads on how to "orderby" my results in a dynamic list template?

Thanks!
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: Dynamic List OrderBy in VM Template?

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Well, if you call getRecords() w/ the record set id, the status value, -1 for the start/end, and the order by comparator you can control the sorting...

Alternatively I'd probably create a class/method to proxy the call to getRecords() passing in the right stuff. Would be easier to use from the VM template...
12年前 に James Burris によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 4 参加年月日: 12/03/16 最新の投稿
David H Nebinger:
Well, if you call getRecords() w/ the record set id, the status value, -1 for the start/end, and the order by comparator you can control the sorting...

Alternatively I'd probably create a class/method to proxy the call to getRecords() passing in the right stuff. Would be easier to use from the VM template...


I'm probably blind to the simplicity of this. However, here is where we plugged in the getRecords details:

#set ($ddlRecordsUtil = $serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService"))
#set ($recordSetId = $getterUtil.getLong($reserved_record_set_id.data))
#set ($records = ${ddlRecordsUtil.getRecords($recordSetId,-1,-1,50,ORDER_BY_text4701_DESC)}) < - - HERE
<table class="pp-table"><tr><th>NAME</th><th>FROM YEAR</th><th>TO YEAR</th></tr>
#foreach ($record in $records)
#set ($name = $record.getField("text5549").getValue())
#set ($from-year = $record.getField("text4701").getValue())
#set ($to-year = $record.getField("text5473").getValue())
<tr>
<td><strong>$name</strong></td>
<td>$from-year</td>
<td>$to-year</td>
</tr>
#end
</table>

Of course, the ORDER_BY isn't working. Probably because we haven't defined the field yet. Everything else in the line works fine and makes sense but we must be using the DDL orderby nomenclature incorrectly.
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: Dynamic List OrderBy in VM Template?

Liferay Legend 投稿: 14916 参加年月日: 06/09/02 最新の投稿
Order by in this instance is not a string, it's an implementation of a class, the abstract class OrderByComparator.
thumbnail
10年前 に John Nowlin によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 8 参加年月日: 13/07/05 最新の投稿
I am also struggling with this. Can you provide a simple WORKING example?
10年前 に nadi h によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 21 参加年月日: 13/07/23 最新の投稿
In portlets :



records = DDLRecordLocalServiceUtil.getRecords(record_set_id, -1, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
    OrderByComparatorFactoryUtil.create("DDLRecord", "MODIFIEDDATE", true));



must be converted to template code.
10年前 に nadi h によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 21 参加年月日: 13/07/23 最新の投稿
For example, if you want to sort records by modified date (freemarker code):


&lt;#assign OrderByComparatorFactoryUtil = staticUtil["com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil"]&gt;
&lt;#assign orderby = OrderByComparatorFactoryUtil.create("DDLRecord", ["MODIFIEDDATE", false])&gt; 

&lt;#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")&gt;
&lt;#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id, -1, -1, -1, orderby)&gt;

&lt;#if records?has_content&gt;
	&lt;#list records as cur_record&gt;
		#${cur_record.recordId}<br>
	<!--#list-->
<!--#if-->
9年前 に Stéphane Faure によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 14 参加年月日: 14/04/22 最新の投稿
I am using Liferay 6.2 and this code does not work for me...
Do you have any idea of the problem?
Thanks in advance.
______________________________________

<#assign OrderByComparatorFactoryUtil = staticUtil["com.liferay.portal.kernel.util.OrderByComparatorFactoryUtil"]>
<#assign orderby = OrderByComparatorFactoryUtil.create("DDLRecord", ["attribut_n_1", false])>
<#assign DDLRecordLocalService = serviceLocator.findService("com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService")>
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id, -1, -1, -1, orderby)>


________ This code generates the following error __________

Error on line 16, column 1 in 10154#10194#24735
DDLRecordLocalService.getRecords(reserved_record_set_id, -1, -1, -1, orderby) is undefined.
It cannot be assigned to records

___________________________________________

This works when I replace :
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id, -1, -1, -1, orderby)>

by
<#assign records = DDLRecordLocalService.getRecords(reserved_record_set_id)>


But then, the possibility to order the list is lost...
9年前 に Justin Stanczak によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 9 参加年月日: 13/12/06 最新の投稿
I'm getting the same issue. Did you find the solution for this?
thumbnail
9年前 に Christoph Rabel によって更新されました。

RE: Dynamic List OrderBy in VM Template?

Liferay Legend 投稿: 1554 参加年月日: 09/09/24 最新の投稿
Um, reserved_record_set_id is null.

Just tried it. If you create a new ddl and use its ID, it works:
<#assign records = DDLRecordLocalService.getRecords(20030, -1, -1, -1, orderby )>

In my case, the ID is 20030, I just looked it up in control panel.
thumbnail
9年前 に Anderson Perrelli によって更新されました。

RE: Dynamic List OrderBy in VM Template?

Junior Member 投稿: 81 参加年月日: 13/06/12 最新の投稿
You could use Velocity SortTool, Liferay is ready to use in its velocity templates.

Take a look here

http://www.liferay.com/community/wiki/-/wiki/Main/CMS+Template+%28Velocity%29#section-CMS+Template+(Velocity)
thumbnail
8年前 に Nicolas MEURET によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 3 参加年月日: 13/02/08 最新の投稿
Here is the solution I found to sort DDL in VM template :

#set ($ddlRecordService = $serviceLocator.findService('com.liferay.portlet.dynamicdatalists.service.DDLRecordLocalService'))
#set ($records = $ddlRecordService.getRecords($reserved_record_set_id))

#if(!$records.isEmpty())

    #set ($sortRecords= [])
    #foreach ($cur_rec in $records )
        #set ($tmp = $sortRecords.add( {"Order" : $cur_rec.getFieldValue("Order", $locale) , "obj" : $cur_rec }))
    #end

	#foreach ($cur_obj in $sortTool.sort( $sortRecords , "Order"))
	
	    #set ($cur_record = $cur_obj.obj)
		
		$cur_record.getFieldValue("firstName", $locale)
		...
		
	#end
	
#end


The trick is to use the Sorter objet + a temp array.

Hope this help somebody ...
thumbnail
7年前 に Alessandro Lachina によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 24 参加年月日: 13/06/12 最新の投稿
Any news in Freemarker?
Ordeby Comparator seems to work only on ddlRecord fileds (creation date , modified date) not on custom filed of the structure..
thumbnail
7年前 に Achmed Tyrannus Albab によって更新されました。

RE: Dynamic List OrderBy in VM Template?

Regular Member 投稿: 158 参加年月日: 10/03/05 最新の投稿
Alessandro Lachina:
Any news in Freemarker?
Ordeby Comparator seems to work only on ddlRecord fileds (creation date , modified date) not on custom filed of the structure..


Hi,

Did you manage this in FreeMarker?
thumbnail
4年前 に Achmed Tyrannus Albab によって更新されました。

RE: Dynamic List OrderBy in VM Template?

Regular Member 投稿: 158 参加年月日: 10/03/05 最新の投稿
In case anyone is trying to do this in Liferay 7.1 (since I have no idea how to sort by DDL field in Free Marker) :
​​​​​​​
#set ($records = $ddlDisplayTemplateHelper.getRecords($reserved_record_set_id))
#if(!$records.isEmpty())
	#set ($sortRecords= [])
	#foreach ($cur_rec in $records )
		#set ($Date_DateObj = $ddlDisplayTemplateHelper.renderRecordFieldValue($cur_rec.getDDMFormFieldValues("DateField").get(0), $locale))
		#set ($tmp = $sortRecords.add( {"Order" : $Date_DateObj , "obj" : $cur_rec }))
	#end
	#foreach ($cur_obj in $sortTool.sort($sortRecords , "Order:desc"))
		#set ($cur_rec = $cur_obj.obj)      
		#set ($theDate = $ddlDisplayTemplateHelper.renderRecordFieldValue($cur_rec.getDDMFormFieldValues("DateField").get(0), $locale))
		$theDate<br>	
	#end
#end 


Hope that helps someone.
thumbnail
4年前 に Manuel Manhart によって更新されました。

RE: Dynamic List OrderBy in VM Template?

New Member 投稿: 9 参加年月日: 13/06/28 最新の投稿
Following entry in stackoverflow works like a charm in 7.1 in Freemarker (at least the answer that iterates twice): https://stackoverflow.com/questions/14337681/freemarker-template-sort-by-one-or-other