2

I have a dataset for Ex:

$scope.friends =
      [{name:'John',  score:'10'},
       {name:'Mary',  score:'19'},
       {name:'Mike',  score:'-21'},
       {name:'Adam',  score:'-35'},
       {name:'Julie', score:'29'}];
}]);

i use this data as a source of ng-repeat,

<tr ng-repeat="friend in friends | orderBy:'-score' ">
  <td>{{friend.name}}</td>
  <td>{{friend.score}}</td>
</tr>

I want to sort the friends according to score in descending order. like below,

Name    Score
-------------
Julie   29
Mary    19
John    10    
Mike    -21
Adam    -35

but i get the output as,

Name    Score
-------------
Julie   29
Mary    19
John    10  
Adam    -35  
Mike    -21

here is a Demo Plunker

note that -21 and -35 are not in correct order in the output, and this is because the score property is a String value. If i change it to int value then all are working as expected. how to overcome this, and please consider that i'am not able to change the type of the score property.

1
  • 2
    This seems to be a valid open issue in Angular. Some suggestions mentioned to get around it. Commented Apr 17, 2015 at 13:25

1 Answer 1

2

What about

<tr ng-repeat="friend in friends | orderBy:'+-score' ">
  <td>{{friend.name}}</td>
  <td>{{friend.score}}</td>
</tr>

Plunker

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.