Solved

Quick Sort on AngularJS sele

Posted on 2013-12-12
2
412 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:charlesbaldo
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:charlesbaldo
ID: 39749852
Thank you.  Apologize for not accepting earlier thought I had
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now