Page 1 of 1

Not able to 'sort' contacts ?

Posted: Fri May 18, 2007 11:46 am
by takara
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)..


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 gid
122 . "\n ORDER BY name"
123 ;
124 $database->setQuery( $query );
125 $rows = $database->loadObjectList();

change line 122 above from:

ORDER BY ordering



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....

Re: Not able to 'sort' contacts ?

Posted: Fri May 18, 2007 6:02 pm
by leadict
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.



Re: Not able to 'sort' contacts ?

Posted: Mon Mar 31, 2008 10:07 pm
by alam813
Any way to do this for 1.5?

Re: Not able to 'sort' contacts ?

Posted: Tue Apr 08, 2008 5:49 pm
by ShlomoAbraham
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!

Re: Not able to 'sort' contacts ?

Posted: Tue Apr 08, 2008 9:03 pm
by alam813
Worked like a charm, thanks!

Re: Not able to 'sort' contacts ?

Posted: Mon Apr 14, 2008 7:36 am
by libby
many thanks
btw, I have also been using the contactinfo module to display the contact info and it's brilliant

Re: Not able to 'sort' contacts ?

Posted: Mon May 05, 2008 2:43 am
by Spiguy
Just want to say thanks...I was just looking for this. Maybe something that should be included as a core option.

Re: Not able to 'sort' contacts ?

Posted: Fri Jul 10, 2009 9:13 pm
by a_khan69
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

Re: Not able to 'sort' contacts ?

Posted: Mon Aug 03, 2009 7:40 am
by oorzaak
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?

Re: Not able to 'sort' contacts ?

Posted: Mon Feb 15, 2010 4:35 pm
by jwbrett
ONE CAUTION: Since this is a hack to the 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.

Re: Not able to 'sort' contacts ?

Posted: Mon Feb 15, 2010 8:59 pm
by ivokwee
seems like adding "&" to the URL does the trick. So I made a custom menu item with the url:


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

Re: Not able to 'sort' contacts ?

Posted: Tue Feb 16, 2010 12:47 am
by jwbrett
@ivokwee ;)
DUH! You are the man! Sometimes the obvious is the most illusive!
Perfect fix...much better than hacking the file.


Re: Not able to 'sort' contacts ?

Posted: Mon Mar 08, 2010 12:06 pm
by Mike Cross
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 "&" 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).


Re: Not able to 'sort' contacts ?

Posted: Sun Nov 14, 2010 8:54 pm
by nick-birch
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.

Re: Not able to 'sort' contacts ?

Posted: Thu Jan 13, 2011 1:36 pm
by michele654
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.