Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Quick Sort on AngularJS sele

Posted on 2013-12-12
2
Medium Priority
?
448 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 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

636 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