Sorting the $_items array according some field

alt=
@dobmat
10 years ago
93 posts
Hi

Is there a way to sort the $_items array in item_display.tpl. Is it a good idea to sort it inside the template code?

Thanks.
updated by @dobmat: 08/25/14 09:29:12PM
paul
@paul
10 years ago
4,326 posts
It can be done in the template, but if it can be done in the jrCore_list call using the order_by parameter that would be a lot better.
What are you trying to do?


--
Paul Asher - JR Developer and System Import Specialist
alt=
@dobmat
10 years ago
93 posts
Sorry, I meant item_list instead of item_detail template. I want the items of a modules to be displayed in alphabetical order rather than in the order of creation time as it is happening now for all modules.

Thanks.
paul
@paul
10 years ago
4,326 posts
For audio, say -

{jrCore_list module="jrAudio" order_by="audio_title ASC" etc. etc. . . . }

Change the module and order_by parameters to suit for other modules/lists.
hth
Pa


--
Paul Asher - JR Developer and System Import Specialist
alt=
@dobmat
10 years ago
93 posts
I'm not able to determine where I should put the above code. I tried several places but the template is showing blank page. Please help me here. Below is my item_list template.

{if isset($_items)}
 {foreach from=$_items item="item"}
  {if isset($item.venues_image_name)}
   <div class="item">
    <div class="container">
     <div class="row">
      <div class="col2">
       <div class="block_image">
        <a href="{jrProfile_item_url module="gsVenue"
        profile_url=$item.profile_url item_id=$item._item_id 
        title=$item.venues_title}">{jrCore_module_function 
        function="jrImage_display" module="gsVenue"
        type="venues_image" class="iloutline" item_id=$item._item_id 
        size="xsmall" crop="auto" alt=$item.user_name}</a>
       </div>
      </div>
     <div class="col10 last">
      <div class="p5">
       <h3><a href="{jrProfile_item_url module="gsVenue" 
       profile_url=$item.profile_url 
       item_id=$item._item_id title=$item.venues_title}">
       {$item.venues_title}</a></h3><br>
       <span class="normal">{$item.venues_text|
        jrCore_format_string:$item.profile_quota_id|
	strip_tags|truncate:180}</span>
      </div>
     </div>
    </div>
   </div>
  </div>
 {/if}
 {/foreach}
{/if}

Thanks.
updated by @dobmat: 07/25/14 07:10:20AM
paul
@paul
10 years ago
4,326 posts
That looks like the code of the 'item_list' that the jrCore_list calls.
Assuming that this is a Venue module following the conventional JR module structure, the jrCore_list call that you need to modify will be in the /templates/item_index.tpl file.


--
Paul Asher - JR Developer and System Import Specialist
alt=
@dobmat
10 years ago
93 posts
I tried it in the 'item_index' template. I does not work. This is what I put in 'item_index' template.

<div class="block_content">
        {jrCore_list module="gsVenue" profile_id=$_profile_id 
	 order_by="venues_title  ASC" pagebreak="6" page=$_post.p pager=true}
</div>

Thanks.
updated by @dobmat: 07/25/14 08:51:44AM
paul
@paul
10 years ago
4,326 posts
Not sure if its the issue but try taking out the two spaces between venues_title and ASC. Leave just one space.
If its still the same, how is it not working? No results at all, or not in the specified order?


--
Paul Asher - JR Developer and System Import Specialist
alt=
@dobmat
10 years ago
93 posts
I tried with single space. Its not working as expected. The items are still sorted in order of their time of creation and not in alphabetical order of venue name.

Thanks.
updated by @dobmat: 07/25/14 12:28:56PM
paul
@paul
10 years ago
4,326 posts
Check that there is a datastore field called 'venues_title'. Are you sure its not 'venue_title', say, or you've not named it something else in your custom module?
Maybe try taking out the ASC bit. It should default to that anyway.
If all else fails, give me access to your site via a support ticket and I'll check it out for you.
Pa


--
Paul Asher - JR Developer and System Import Specialist
brian
@brian
10 years ago
10,148 posts
Yeah this should work no problem - I would check that the key is named properly.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
The field name is correct and it is there for every item of my venue module. I removed ASC and tried, still no difference. Does it only work for numerical fields and not for text strings? Please let me know how I can put a support ticket.

Thanks.
paul
@paul
10 years ago
4,326 posts
As Brian said, it should work!!

https://www.jamroom.net/ticket/create


--
Paul Asher - JR Developer and System Import Specialist
brian
@brian
10 years ago
10,148 posts
Yeah this is used all over the place - doesn't matter if it is a string or number. Make sure you are running in developer mode so caching is disabled.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
I'm getting 'You do not have the proper privileges to perform that action!' if I click on the link you gave. Seems its not working for any field in my module's item.

Thanks.
michael
@michael
10 years ago
7,715 posts
How did you create this module? if you used jrAparna then check your table names again because a module named 'gsVenue' would create a prefix of 'venue_' not 'venues_'
alt=
@dobmat
10 years ago
93 posts
I didn't use the jrAparna module to write my module. I deleted my module from my Jamroom install, changed the datastore field names and tested again. I gave order by as venue_title in ascending order, but still its sorting according to item ID. Please see the attachment below.

Thanks.
jpg
 •  103KB


updated by @dobmat: 07/26/14 03:07:24AM
brian
@brian
10 years ago
10,148 posts
Unfortunately I'm not sure what to tell you - I'm fairly certain this works without issue, so it's got to be something you've done with your new module setup (i.e. you changed some things but not all).


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 07/26/14 07:40:32AM
michael
@michael
10 years ago
7,715 posts
Here's a video for you walking through creating the module with aparna, then adding some list items, then sorting the list items and reversing the order.

"How to order a list made by {jrCore_list}"
How to order a list made by {jrCore_list}

--update--
I've also added that video to the aparna modules docs:

"jrAparna"
https://www.jamroom.net/the-jamroom-network/documentation/modules/853/jraparna
updated by @michael: 07/26/14 03:44:47PM

Tags