The Joomla! Forum ™





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 
Author Message
PostPosted: Fri May 18, 2007 11:46 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 04, 2006 6:17 am
Posts: 20
Apparently there are a lot of people wondering how to sort the contacts list alphabetically...

This is pretty simple with a small php hack, in fact a single word. When in comes to sorting, you are always better to retrieve the results sorted from mysql rather than trying to sort the array (simple if its a 1d array, otherwise inefficient)..

open yoursite.com\components\com_contact\contact.php

I'm using 1.0.12 and its line 122 that you want to go to or search for the following code:

115 if ( $catid ) {
116 // url links info for category
117 $query = "SELECT *"
118 . "\n FROM #__contact_details"
119 . "\n WHERE catid = " . (int) $catid
120 . "\n AND published =1"
121 . "\n AND access <= " . (int) $my->gid
122 . "\n ORDER BY name"
123 ;
124 $database->setQuery( $query );
125 $rows = $database->loadObjectList();

change line 122 above from:

ORDER BY ordering

to:

ORDER BY name

voila!
you now have the contacts list ordered by the name of the contact alphabetically.

Of course, this will ignore the ordering you have done in the backend by using the arrows.

This can be applied to any field by changing the ordering to another field name like position or whatever....

to get a list of the field names stored in the array use var_dum($array) somewhere on your form....


Last edited by humvee on Sat May 19, 2007 12:34 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Fri May 18, 2007 6:02 pm 
Joomla! Guru
Joomla! Guru

Joined: Thu Oct 05, 2006 12:13 am
Posts: 810
Hi takara,

This is a good example of core hack to publish at Custom Joomla! Development board => Core Hacks and Patches

That is the proper place for this type of posts, and i'm sure that there it will be very useful to many users.

Thanks

Leandro

_________________
"The skill of writing is to create a context in which other people can think" - Edwin Schlossberg.


Top
 Profile  
 
PostPosted: Mon Mar 31, 2008 10:07 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Feb 29, 2008 6:07 pm
Posts: 6
Any way to do this for 1.5?


Top
 Profile  
 
PostPosted: Tue Apr 08, 2008 5:49 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Tue Apr 08, 2008 5:21 pm
Posts: 1
alam813 wrote:
Any way to do this for 1.5?


I did this, it seems to work:
In /components/com_contact/views/category/view.html.php

Line 41: $filter_order = JRequest::getVar('filter_order', 'cc.ordering', '', 'cmd');

Change 'cc.ordering' to the field you want to be ordered by. I used alias instead of name. Whenever I add a contact, I set alias to be lastname-firstname, this way it will sort alphabetically by last name. So my line 41 looks like:

Line 41: $filter_order = JRequest::getVar('filter_order', 'alias', '', 'cmd');

Good luck!


Top
 Profile  
 
PostPosted: Tue Apr 08, 2008 9:03 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Feb 29, 2008 6:07 pm
Posts: 6
Worked like a charm, thanks!


Top
 Profile  
 
PostPosted: Mon Apr 14, 2008 7:36 am 
Joomla! Enthusiast
Joomla! Enthusiast

Joined: Mon Oct 31, 2005 1:01 pm
Posts: 199
many thanks
btw, I have also been using the contactinfo module to display the contact info and it's brilliant


Top
 Profile  
 
PostPosted: Mon May 05, 2008 2:43 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Feb 23, 2008 11:20 pm
Posts: 23
Just want to say thanks...I was just looking for this. Maybe something that should be included as a core option.


Top
 Profile  
 
PostPosted: Fri Jul 10, 2009 9:13 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri May 23, 2008 8:01 pm
Posts: 16
how can i do this to sort by multiple fields eg. ORDER BY con_position, name

I used the code like this, but it did not work for me:

$filter_order = JRequest::getVar('filter_order', 'con_position, name', '', 'cmd');


Any ideas? Thanks


Top
 Profile  
 
PostPosted: Mon Aug 03, 2009 7:40 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Tue Feb 17, 2009 2:19 pm
Posts: 20
Works great indeed! Thanks a lot.

Yet I have one more question. Is there a way to save the edited view.html.php file in my template folder, along with other template overrides?


Top
 Profile  
 
PostPosted: Mon Feb 15, 2010 4:35 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun May 06, 2007 7:57 pm
Posts: 22
ONE CAUTION: Since this is a hack to the CORE...it could easily be erased in an upcoming Joomla update. If Joomla does some work to this file and includes it in a future update, the hack will of course be overwritten and will have to be put back.

So this is something you'll have to keep track of when future updates are released.


Top
 Profile  
 
PostPosted: Mon Feb 15, 2010 8:59 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Mon Feb 15, 2010 8:56 pm
Posts: 2
seems like adding "&filter_order=cd.name" to the URL does the trick. So I made a custom menu item with the url:

index.php?option=com_contact&view=category&catid=38&Itemid=148&filter_order=cd.name

I really wish they'd put is as standard parameter though...


Top
 Profile  
 
PostPosted: Tue Feb 16, 2010 12:47 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun May 06, 2007 7:57 pm
Posts: 22
@ivokwee ;)
DUH! You are the man! Sometimes the obvious is the most illusive!
Perfect fix...much better than hacking the file.

Thanks!
John.


Top
 Profile  
 
PostPosted: Mon Mar 08, 2010 12:06 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sun Feb 07, 2010 4:41 pm
Posts: 16
I think it's even easier than that.

Create it as a Contact Category internal link and save it as normal.

Then edit the menu item. Change it's type to "external link". You will find that it retains all of the parameters that it had when it was a "contact category" link but now you can edit the link itself to add "&filter_order=cd.name" on to the end. It retains all of the look and feel of the original and because it's using a relative link it will still work if you change the base URL, e.g. to move from development to production environment.

You do need to shut down the front-end browser and re-start it to get the effect. A simple page refresh won't show it (no need to restart the backend).

Mike


Top
 Profile  
 
PostPosted: Sun Nov 14, 2010 8:54 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Fri Feb 05, 2010 9:08 pm
Posts: 8
Good approach. The only point I would make is that External links don't have many parameters and so, for example, I don't think you can show the Limit Box or Feed Link options.
There may be other detailed limitations that I have not checked, but if none of these matter it is an easy fix.


Top
 Profile  
 
PostPosted: Thu Jan 13, 2011 1:36 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon Apr 21, 2008 3:56 pm
Posts: 42
Location: North Carolina
Am I missing something, or isn't the "order by" field in the backend list enough? Too cumbersome? I manage 30 people in the contact list, and have them display just the way I want them through the Order By field on the Contacts page.

_________________
-Michele

Dear God, I have a problem. It's me.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 posts ] 



Who is online

Users browsing this forum: 4group and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group