Not able to 'sort' contacts ?
-
- Joomla! Apprentice
- Posts: 20
- Joined: Sat Nov 04, 2006 6:17 am
Not able to 'sort' contacts ?
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 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....
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 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.
-
- Joomla! Guru
- Posts: 809
- Joined: Thu Oct 05, 2006 12:13 am
Re: Not able to 'sort' contacts ?
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
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.
-
- Joomla! Apprentice
- Posts: 6
- Joined: Fri Feb 29, 2008 6:07 pm
Re: Not able to 'sort' contacts ?
Any way to do this for 1.5?
-
- Joomla! Fledgling
- Posts: 1
- Joined: Tue Apr 08, 2008 5:21 pm
Re: Not able to 'sort' contacts ?
I did this, it seems to work:alam813 wrote:Any way to do this for 1.5?
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!
-
- Joomla! Apprentice
- Posts: 6
- Joined: Fri Feb 29, 2008 6:07 pm
Re: Not able to 'sort' contacts ?
Worked like a charm, thanks!
-
- Joomla! Enthusiast
- Posts: 215
- Joined: Mon Oct 31, 2005 1:01 pm
Re: Not able to 'sort' contacts ?
many thanks
btw, I have also been using the contactinfo module to display the contact info and it's brilliant
btw, I have also been using the contactinfo module to display the contact info and it's brilliant
-
- Joomla! Apprentice
- Posts: 23
- Joined: Sat Feb 23, 2008 11:20 pm
Re: Not able to 'sort' contacts ?
Just want to say thanks...I was just looking for this. Maybe something that should be included as a core option.
-
- Joomla! Apprentice
- Posts: 16
- Joined: Fri May 23, 2008 8:01 pm
Re: Not able to 'sort' contacts ?
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
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
-
- Joomla! Apprentice
- Posts: 40
- Joined: Tue Feb 17, 2009 2:19 pm
Re: Not able to 'sort' contacts ?
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?
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?
-
- Joomla! Apprentice
- Posts: 22
- Joined: Sun May 06, 2007 7:57 pm
Re: Not able to 'sort' contacts ?
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.
So this is something you'll have to keep track of when future updates are released.
-
- Joomla! Fledgling
- Posts: 2
- Joined: Mon Feb 15, 2010 8:56 pm
Re: Not able to 'sort' contacts ?
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...
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...
-
- Joomla! Apprentice
- Posts: 22
- Joined: Sun May 06, 2007 7:57 pm
Re: Not able to 'sort' contacts ?
@ivokwee
DUH! You are the man! Sometimes the obvious is the most illusive!
Perfect fix...much better than hacking the file.
Thanks!
John.
DUH! You are the man! Sometimes the obvious is the most illusive!
Perfect fix...much better than hacking the file.
Thanks!
John.
-
- Joomla! Apprentice
- Posts: 17
- Joined: Sun Feb 07, 2010 4:41 pm
Re: Not able to 'sort' contacts ?
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
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
-
- Joomla! Apprentice
- Posts: 9
- Joined: Fri Feb 05, 2010 9:08 pm
Re: Not able to 'sort' contacts ?
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.
There may be other detailed limitations that I have not checked, but if none of these matter it is an easy fix.
- michele654
- Joomla! Intern
- Posts: 75
- Joined: Mon Apr 21, 2008 3:56 pm
- Location: North Carolina
Re: Not able to 'sort' contacts ?
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.
Dear God, I have a problem. It's me.