javascript - Why are my ng-repeat items not filtering as expected here? -


plnkr: http://plnkr.co/edit/q34j9szbleggc4jkcnum?p=preview

i have simple array called tags, contains 4 objects tweets value , vol value.

enter image description here

when click order tweets, or order vol buttons expect numbers make sense, going high low or low high, numbers out of order.

markup:

 <div class="sidebar" ng-controller="sidebar">   <header class="my-header">     <button ng-click="reorderbytweets()">order tweets</button>     <button ng-click="reorderbyvol()">order vol</button>   </header>   <ul>     <li ng-repeat="t in tags" ng-mouseleave="leavetag(t)">       <div class="tag-container">         <div class="tag border1"              ng-mouseover="showtagdetails(t)">{{t.name}} | tweets: {{t.tweets}} | vol: {{t.vol}}</div>         <tag-details tag="t"></tag-details>       </div>     </li>   </ul> </div> 

javascript:

$scope.tags.push(   {     name: 'item 1 ',      tweets: '412',     vol: '50'   },   {     name: 'item 2 ',      tweets: '10',     vol: '500'   },   {     name: 'item 3 ',      tweets: '67',     vol: '5'   },   {     name: 'item 4 ',      tweets: '0',     vol: '30'   } ); 

the functions:

function reorderbytweets() {     console.log('reorderbytweets');     vs.orderreverse = !vs.orderreverse;     $scope.tags = $filter('orderby')($scope.tags, 'tweets', vs.orderreverse);     console.log('vs.orderreverse = ', vs.orderreverse); // true or false     console.log('$scope.tags = ', $scope.tags); }  function reorderbyvol() {     console.log('reorderbyvol');     vs.orderreverse = !vs.orderreverse;     $scope.tags = $filter('orderby')($scope.tags, 'vol', vs.orderreverse);     console.log('vs.orderreverse = ', vs.orderreverse); // true or false     console.log('$scope.tags = ', $scope.tags); } 

as can see screenshot below, while ordering vol. item vol:5 should come last after vol:30

enter image description here


update: looks it's filtering on first digit in numbers? why not take entire number?

filtering tweets clicked once:

enter image description here

filtering tweets clicked 2nd time:

enter image description here

you're ordering string value done alphabetical order.

'10' '5' '30'

the string order of 10 / 30 / 5.

changing 'vol' & 'tweets' numbers:

  $scope.tags.push(     {       name: 'item 1 ',        tweets: 412,       vol: 50     },     {       name: 'item 2 ',        tweets: 10,       vol: 216     },     {       name: 'item 3 ',        tweets: 67,       vol: 15     },     {       name: 'item 4 ',        tweets: 0,       vol: 30     }   ); 

sorts tweets correctly.

enter image description here


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -