?
Solved

Quick Sort on AngularJS sele

Posted on 2013-12-12
2
Medium Priority
?
451 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
2 Comments
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one 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…
Suggested Courses

864 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