sorting troubles in ng-options

3,020 views
Skip to first unread message

Mike Brennan

unread,
Jan 18, 2013, 8:48:30 AM1/18/13
to ang...@googlegroups.com


http://jsfiddle.net/mjb14/5PsWJ/1/

Rather than having a simple array of objects, I am using an object to power the <select> box.  The fiddle has the select working fine, I am just having trouble getting the order by to work.  Is it possible to sort on a key of a value?  I need the data in this structure because I use it to do lookups.  My alternative right now is to generate the data 2x in 2 different formats, but that isn't ideal.



  $scope.metaData = {
    "column": {
        "application_id": {
            "foreign_key_data": {
                "1": {
                    "application_name": "mojo_rose",
                    "descr": "Mojo Rose framework project",
                    "application_id": "1"
                },
                "2": {
                    "application_name": "eas",
                    "descr": "EAS utility apps",
                    "application_id": "2"
                },
                "3": {
                    "application_name": "app_security",
                    "descr": "Application Security project",
                    "application_id": "3"
                }
            }
        }
    }
};

HTML:

 <select id="form-application_id" ng-model="formData.application_id" ng-options="k as v.application_name for (k,v) in metaData.column.application_id.foreign_key_data" >
<option value=""></option>
</select>

Pawel Kozlowski

unread,
Jan 18, 2013, 1:40:10 PM1/18/13
to ang...@googlegroups.com
Hi!


It kind of makes sense since AFAIK you can't grantee iteration order over object keys in JavaScript. AngularJS would have to change your data model behind the scenes...

Cheers,
Pawel


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
 
 



--
Question? Send a fiddle (http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk (http://plnkr.co/)
Need help with jsFiddle? Check this: http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go: http://angular-ui.github.com/

Carl Chouinard

unread,
Mar 8, 2014, 7:12:26 AM3/8/14
to ang...@googlegroups.com
You can use a custom filter to do what you want. Check this blog post that describe the filter: http://justinklemm.com/angularjs-filter-ordering-objects-ngrepeat/

Kumar R

unread,
Mar 8, 2014, 7:36:39 AM3/8/14
to angular
Welcome Carl Chouinard,

refer this link you can get some idea:


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.

To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages