Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8576955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:03:06+00:00 2026-06-11T20:03:06+00:00

I’m using the jquery autocomplete plugin that comes with the symfony sfFormExtra plugin. /*

  • 0

I’m using the jquery autocomplete plugin that comes with the symfony sfFormExtra plugin.

/*
* jQuery Autocomplete plugin 1.1
*
* Copyright (c) 2009 Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
*   http://www.opensource.org/licenses/mit-license.php
*   http://www.gnu.org/licenses/gpl.html
*
* Revision: $Id: jquery.autocomplete.js 15 2009-08-22 10:30:27Z joern.zaefferer $
*/

It does seem to sort json results according to the key, but I can’t find any mention of sort options in the code.

I would like the results sorted like returned from the server.

The results are build like this

public function doMemberSelectForSelectById($q, $limit){

    $query = $this->retrieveMemberOrganisations($this->createUnrestrictedQuery('o'))->
      andWhere("o.name like '%".$q."%'")->
      orderBy("o.name")->
      limit(intval($limit));

    $org_data = $query->execute();
    $orgs = array();
    foreach ($org_data as $org){
        $orgs[$org->getId()] = $org->getName();
    }
    return $orgs;
}

$orgs = Doctrine_Core::getTable('Organisation')->
    doMemberSelectForSelectById($request->getParameter('q'), $request->getParameter('limit'));
echo $this->renderText(json_encode($orgs));
    }
return sfView::NONE;

The result in Chrome Dev Tools is (ordered by name)

{
    "1781": "1st Mechanical \/ 1st Maintenance",
    "1771": "Acco Building Ltd",
    "203": "Active Welding Limited",
    "443": "Aircon Commissioning & Services Ltd",
    "588": "Akon Electrical Engineering Limited",
    "625": "Alaska Interiors Ltd",
    "796": "Alutech Windows & Doors Ltd",
    "584": "Arrow International Ltd"....
}

The javascript that triggers it is here

jQuery(document).ready(function() {

    jQuery("#autocomplete_rsvpCompany1").focus(function({
         jQuery(this).val('');});
             jQuery("#autocomplete_rsvpCompany1").autocomplete(
                 'http://www.nzgbc.org.nz/index.php?option=com_nzgbc_member&uri=%2Forganisation%2FjsonListMember%2Faction',
                 jQuery.extend({}, {
                     dataType: 'json',
                     minChars: 0,
                     delay:0,
             max:700,
                     scroll: true, 
                     parse: function(data) {
                 var parsed = [];
                 for (key in data) {
                             parsed[parsed.length] = { data: [ data[key], key ], value: data[key], result: data[key] };
                 }
                 return parsed;
                 }
         }, { })
        ).result(function(event, data) {
            jQuery('#rsvpCompany1').val(data[1]);
        });

How can I achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:03:08+00:00Added an answer on June 11, 2026 at 8:03 pm

    You should change the “parse” method as follows:

    parse: function(data) {
      var parsed = [];
      for (key in data) {
        parsed[parsed.length] = { 
          data: [ data[key], key ], 
          value: data[key], 
          result: data[key] 
        };
      }
      parsed.sort(function (a, b){
        var aKey = a.value;
        var bKey = b.value;
        return ((aKey < bKey) ? -1 : ((aKey > bKey) ? 1 : 0));
      });
      return parsed;
    }
    

    The problem is that the “data” array has a numeric key, so when you loop over the “data” elements in your “for” loop, you are adding the elements to the “parsed” array in the numeric order (eg.: 203, 443, 584, 588, etc.), so after adding all the elements to the “parsed” array you have to sort it by “data[key]”, and not by “key”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.