CMS Development

abdulshahid
Participant | Diamond Partner
Participant | Diamond Partner

Sort Repeater fields

Hi

 

Is there a way to sort repeater fields please?

 

We have created a repeater module with a date field in it, we would like the output to be dropped in asc/desc date order. We looked at the 'sort' filter but cannot get it to work - 

 

 

{% for item in module.description|sort(False, False, 'date_field') %}
{{ item.date_field }}<br>
{{ item.name }}
{% endfor %}

The error we get is -  

Error:Invalid argument in 'sort': 3rd argument with value 'date_field' must be a valid attribute of every item in the list

 

0 Upvotes
3 Replies 3
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Sort Repeater fields

@abdulshahid 

 

Hmm i'm kinda at a loss and cant replicate. Maybe the full code could shed some light?

 

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
Kevin-C
Recognized Expert | Partner
Recognized Expert | Partner

Sort Repeater fields

Hey @abdulshahid 

 

The error leads me to believe that one or more of you items in the repeater has an empty field.

 

You also used "module.description" in the loop. If that property isn't available you won't be able to loop through it.

Kevin Cornett - Sr. Solutions Architect @ BridgeRev
abdulshahid
Participant | Diamond Partner
Participant | Diamond Partner

Sort Repeater fields

Thanks for your reply Kevin

'module.description' is the group name for the repeater fields and there is data in the fields with zero empty fields. The code used above is not the exact code but a condensed version of it

0 Upvotes