Not able to 'sort' contacts ?

Your code modifications and patches you want to share with others.
takara
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Sat Nov 04, 2006 6:17 am

Not able to 'sort' contacts ?

Postby takara » Fri May 18, 2007 11:46 am

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.

leadict
Joomla! Guru
Joomla! Guru
Posts: 809
Joined: Thu Oct 05, 2006 12:13 am

Re: Not able to 'sort' contacts ?

Postby leadict » Fri May 18, 2007 6:02 pm

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.

alam813
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Feb 29, 2008 6:07 pm

Re: Not able to 'sort' contacts ?

Postby alam813 » Mon Mar 31, 2008 10:07 pm

Any way to do this for 1.5?

ShlomoAbraham
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Apr 08, 2008 5:21 pm

Re: Not able to 'sort' contacts ?

Postby ShlomoAbraham » Tue Apr 08, 2008 5:49 pm

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!

alam813
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Fri Feb 29, 2008 6:07 pm

Re: Not able to 'sort' contacts ?

Postby alam813 » Tue Apr 08, 2008 9:03 pm

Worked like a charm, thanks!

libby
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 213
Joined: Mon Oct 31, 2005 1:01 pm

Re: Not able to 'sort' contacts ?

Postby libby » Mon Apr 14, 2008 7:36 am

many thanks
btw, I have also been using the contactinfo module to display the contact info and it's brilliant

Spiguy
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Sat Feb 23, 2008 11:20 pm

Re: Not able to 'sort' contacts ?

Postby Spiguy » Mon May 05, 2008 2:43 am

Just want to say thanks...I was just looking for this. Maybe something that should be included as a core option.

a_khan69
Joomla! Apprentice
Joomla! Apprentice
Posts: 16
Joined: Fri May 23, 2008 8:01 pm

Re: Not able to 'sort' contacts ?

Postby a_khan69 » Fri Jul 10, 2009 9:13 pm

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

oorzaak
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Tue Feb 17, 2009 2:19 pm

Re: Not able to 'sort' contacts ?

Postby oorzaak » Mon Aug 03, 2009 7:40 am

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?

jwbrett
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Sun May 06, 2007 7:57 pm

Re: Not able to 'sort' contacts ?

Postby jwbrett » Mon Feb 15, 2010 4:35 pm

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.

ivokwee
Joomla! Fledgling
Joomla! Fledgling
Posts: 2
Joined: Mon Feb 15, 2010 8:56 pm

Re: Not able to 'sort' contacts ?

Postby ivokwee » Mon Feb 15, 2010 8:59 pm

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

jwbrett
Joomla! Apprentice
Joomla! Apprentice
Posts: 22
Joined: Sun May 06, 2007 7:57 pm

Re: Not able to 'sort' contacts ?

Postby jwbrett » Tue Feb 16, 2010 12:47 am

@ivokwee ;)
DUH! You are the man! Sometimes the obvious is the most illusive!
Perfect fix...much better than hacking the file.

Thanks!
John.

Mike Cross
Joomla! Apprentice
Joomla! Apprentice
Posts: 17
Joined: Sun Feb 07, 2010 4:41 pm

Re: Not able to 'sort' contacts ?

Postby Mike Cross » Mon Mar 08, 2010 12:06 pm

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

nick-birch
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri Feb 05, 2010 9:08 pm

Re: Not able to 'sort' contacts ?

Postby nick-birch » Sun Nov 14, 2010 8:54 pm

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.

User avatar
michele654
Joomla! Apprentice
Joomla! Apprentice
Posts: 48
Joined: Mon Apr 21, 2008 3:56 pm
Location: North Carolina

Re: Not able to 'sort' contacts ?

Postby michele654 » Thu Jan 13, 2011 1:36 pm

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.


Return to “Core Hacks and Patches”

Who is online

Users browsing this forum: No registered users and 0 guests