Angularjs sorting by time 24hrs -


i want implement sorting table fields. have 1 column shows time. here example tried

  <tr><td ng-click="predicate = 'appointmenttime'; reverse=!reverse">admittime</td></tr>     <tr ng-cloak ng-repeat='listitem in apptlist | filterencounters:searchmodel | orderby:predicate:reverse' ng-class='rowclass(listitem)'>     <td>{{listitem.appointmenttime}}</td>     </tr> 

above code working, sorting based in & pm

enter image description here

i sort 24hrs.

here sample code custom filter:

i've used moment.js custom sorting here.

   angular.module("app", [])  .controller("cont", function($scope){    $scope.apptlist  = [{  time : "01:00 pm"    },    {  time : "02:05 pm"    },    {  time : "10:42 am"    },    {  time : "10:44 am"    },    {  time : "10:45 am"    }];  })  .filter('customorderby', function () {     return function (arr, parameter) {   return arr.sort(function(a, b) {     return moment(b.time, "hh:mm a").diff(moment(a.time, "hh:mm a")) > 0 ? -1 : 1;   });  };  });
<html ng-app="app">  <head>  <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.2/angular.min.js"></script>    <script src="http://momentjs.com/downloads/moment.min.js"></script>    <meta charset="utf-8">    <title>js bin</title>  </head>  <body ng-controller="cont">  <ul>    <li ng-repeat="app in apptlist | customorderby">{{app.time}}</li>    </ul>  </body>  </html>    


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -