I am trying to use ng-repeat with a dictionary style syntax and apply an order to the key value.
(key, value) in something | orderBy:'key'
It seems OrderBy isn't working as expected
Example here http://jsfiddle.net/mhXuW/
I am trying to use ng-repeat with a dictionary style syntax and apply an order to the key value.
(key, value) in something | orderBy:'key'
It seems OrderBy isn't working as expected
Example here http://jsfiddle.net/mhXuW/
I created a custom filter to make this possible for a select list:
the select list ng-options then reads as follows:
Here's a good work around (angular-toArrayFilter):
Instead of using orderby filter which only supports arrays and not objects. You can write your own filter like this I took the code from Justin Klemm http://justinklemm.com/angularjs-filter-ordering-objects-ngrepeat/ and added support for specifying multiple ordering fields. The filter example below is to filter based on properties in the values but you can easily change it to filter based on the key as well.
Then inside your html5 web page use it like so where statistics is a map/dictionary with key value pairs.
The parameters to orderBy must match property names in an array of objects.
Your data needs to look something like this:
Then a filter like this will work:
Fiddle.
Note that orderBy works on the entire array (
something
in your sample code above) and it returns a sorted array. orderBy doesn't know anything aboutkey
andvalue
.this is not implemented. please see here:
https://github.com/angular/angular.js/issues/1286
EDIT (Aug 27, 2013): this issue seems to be resolved now.
As akonsu says, the feature has been requested here. However, I still couldn't get it to work with the latest (1.3.0) beta.
There's a nice workaround buried in the comments (note this requires underscore, and you'll have to replace references to 'key' with 'value.$key' in the above example):