CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Sorting Event Locations
Pages: [1]

Author Topic: Sorting Event Locations  (Read 561 times)

Dwiding

  • I post frequently
  • ***
  • Posts: 165
  • Karma: 8
  • CiviCRM version: 3.3.3
  • CMS version: Joomla 1.5.x
Sorting Event Locations
July 06, 2011, 05:52:29 pm
Is there a way to sort the "Use Location" field? It seems to just list in the order that locations were entered and my client would like them sorted by alpha.

thanks!

Dallas


Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Sorting Event Locations
July 07, 2011, 02:04:11 am

In recent versions, the locations are sorted by:

Address Name, Address City, Address "Street Address"

which seems a bit logical

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Dwiding

  • I post frequently
  • ***
  • Posts: 165
  • Karma: 8
  • CiviCRM version: 3.3.3
  • CMS version: Joomla 1.5.x
Re: Sorting Event Locations
July 07, 2011, 07:02:07 am
Hi Lobo,

We are on 3.4.4 and it appears to be sorting in the order entered. Screenshot attached.

Thanks!

Dallas

Dave Greenberg

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 5760
  • Karma: 226
    • My CiviCRM Blog
Re: Sorting Event Locations
July 07, 2011, 03:20:21 pm
Hi Dallas - It's a bit tough to come up with a sort for this dropdown that works nicely for a wide variety of users :-( The current sort order - see line 1594 in CRM/Event/BAO/Event.php - is:

ORDER BY sp.name, ca.city, ca.street_address ASC

... i.e. State followed by City followed by Street Address. And looking at your screen print - that's how it's sorted. This works nicely for organizations with event venues scattered across lots of states and cities. However for your situation it's not great. Initially I couldn't think of a non-hack way to change it for your needs - but then I realized you could probably use jQuery to change the select list sort. I did a quick search for that and came up with several examples. Not sure  this is the best / easiest - but it worked for me in a quick experiment.

The best part is you can append this to the template using the new 'append custom code to template' feature so it should be pretty future proof and easy to maintain. You'll be creating CRM/Event/Form/ManageEvent/Location.extra.tpl in your custom templates tree, with the jQuery code below (or some variation) in the file.

http://civicrm.org/blogs/dave-greenberg/now-its-easier-add-custom-behaviors-templates

Code: [Select]
{literal}
<script>
    // get the select
    var $dd = $('#loc_event_id');
    if ($dd.length > 0) { // make sure we found the select we were looking for

        // save the selected value
        var selectedVal = $dd.val();

        // get the options and loop through them
        var $options = $('option', $dd);
        var arrVals = [];
        $options.each(function(){
            // push each option value and text into an array
            arrVals.push({
                val: $(this).val(),
                text: $(this).text()
            });
        });

        // sort the array by the text
        arrVals.sort(function(a, b){
            return a.text == b.text ? 0 : a.text < b.text ? -1 : 1;
        });

        // loop through the sorted array and set the text/values to the options
        for (var i = 0, l = arrVals.length; i < l; i++) {
            $($options[i]).val(arrVals[i].val).text(arrVals[i].text);
        }

        // set the selected value back
        $dd.val(selectedVal);
    }
</script>
{/literal}
Protect your investment in CiviCRM by  becoming a Member!

Dwiding

  • I post frequently
  • ***
  • Posts: 165
  • Karma: 8
  • CiviCRM version: 3.3.3
  • CMS version: Joomla 1.5.x
Re: Sorting Event Locations
July 08, 2011, 12:53:17 pm
Thanks Dave,  This is perfect.

I'll get my programmer on it as soon as he wraps up some other issues.

Best,

Dallas

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • Sorting Event Locations

This forum was archived on 2017-11-26.