Solved

Quick Sort on AngularJS sele

Posted on 2013-12-12
2
393 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
Comment Utility
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
Comment Utility
Thank you.  Apologize for not accepting earlier thought I had
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

763 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

9 Experts available now in Live!

Get 1:1 Help Now