Solved

Quick Sort on AngularJS sele

Posted on 2013-12-12
2
437 Views
Last Modified: 2014-01-01
I have this select

<select id="selectProperty" ng-model="itemSelected" ng-options="item as item.addressShort for item in listings" ng-change="updateCharts()">

it is filled with

        $rootScope.$on('viewListingDetail', function ($event, listing) {
            for(var j = 0; j < $scope.listings.length; j++) {              
                if(listing.ListingId == $scope.listings[j].ListingId){
                    $scope.itemSelected = $scope.listings[j];
                }
            }
            $scope.selectProperty = listing;
            $scope.updateCharts($scope.itemSelected);
        });

how can I sort by item.addressShort ??
0
Comment
Question by:Charles Baldo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39719522
Using orderBy :
<select id="selectProperty" ng-model="itemSelected" ng-options="item as item.addressShort for item in listings | orderBy:'addressShort'" ng-change="updateCharts()"></select>

Open in new window


Test page : http://jsfiddle.net/t54j9/

function myCtrl($scope) { 
    
    $scope.listings = [
        { ListingId:3, addressShort:"addr3" },
        { ListingId:1, addressShort:"addr1" },
        { ListingId:4, addressShort:"addr4" },
        { ListingId:2, addressShort:"addr2" }
    ];
    
    var listing = { ListingId:3 };
    $scope.updateCharts = function(itm) {
    }
    
    
    for(var j = 0; j < $scope.listings.length; j++) {               
        if(listing.ListingId == $scope.listings[j].ListingId){
            $scope.itemSelected = $scope.listings[j];
        }
    }
    $scope.selectProperty = listing;
    $scope.updateCharts($scope.itemSelected);
}

Open in new window

0
 

Author Closing Comment

by:Charles Baldo
ID: 39749852
Thank you.  Apologize for not accepting earlier thought I had
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question