javascript - AngularJS orderBy filter not working in currency -


angularjs orderby filter not working when use orderby : 'rate' , rest date , product works fine

(function(){  var app = angular.module('tableapp',[ ]);  app.controller('tablecontroller', function($scope){  	$scope.items = [  	    { product: 'lorem ipsum', date: '12-march-2013', rate:'12.35'},  	    { product: 'dolor sit', date: '1-january-2011', rate:'60.54'},  	    { product: 'consectetur', date: '12-december-2014', rate:'12.56'},  	    { product: 'adipisicing', date: '14-noveber-2014', rate:'0.99'},  	    { product: 'do eiusmod', date: '2-noveber-2014', rate:'4.001'},  	    { product: 'magna aliqua', date: '16-february-2014', rate:'06.54'},  	    { product: 'exercitation', date: '30-noveber-2014', rate:'60.32'},  	    { product: 'consequat', date: '5-may-2014', rate:'5.12'},  	    { product: 'reprehenderit', date: '12-april-2014', rate:'8.99'},  	    { product: 'voluptate', date: '18-noveber-2014', rate:'34.54'},  	    { product: 'ugiat nulla', date: '28-june-2014', rate:'55.12'},  	    { product: 'occaecat cupidatat', date: '21-june-2014', rate:'99.54'},  	    { product: 'proident', date: '31-december-2014', rate:'15.50'},  	    { product: 'culpa qui', date: '1-noveber-2014', rate:'34.05'},  	    { product: 'mollit anim', date: '3-noveber-2014', rate:'45.00'}  	]  });  })();
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>  <div class="container" ng-app="tableapp">    <table class="table table-striped table-hover" ng-controller="tablecontroller">      <thead>        <tr>          <th>product</th>          <th>date</th>          <th>amount</th>        </tr>      </thead>      <tbody>        <tr ng-repeat="item in items | orderby : 'rate'">          <td>{{item.product}}</td>          <td>{{item.date}}</td>          <td>{{item.rate | currency:"£"}}</td>        </tr>      </tbody>    </table>  </div>

the attribute rate string, orderby : 'rate' sorts them strings (which totally working).

if want sort them correctly, should remove quotes around rate value (so sorted numbers).

like this:

{ product: 'mollit anim', date: '3-noveber-2014', rate: 45.00 } 

also, remove 0 in 06.54.

http://jsfiddle.net/ruytehtc/ (same html, removed quotes , leading 0)


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -