javascript - ng-repeat: sort by time portion of the date only -


imagine have set of data includes property that's date/time stamp. there number of days, part of date matters in case, time portion of date.

how 1 use time sort collection in ng-repeat expression? require manipulation of kind prior?

i'm attempting replace time stamp property using moment.js after it's populated database.

angular.foreach($scope.timeslots, function (timeslot, index) {     timeslot.begintime = moment(timeslot.begintime).format("hh:mm a");     timeslot.endtime = moment(timeslot.endtime).format("hh:mm a"); }); 

when value used in template, still takes date account when sorting. so, depending on day times added, may out of order.

<tr ng-repeat="timeslot in timeslots | orderby: 'begintime'"> 

i've attempted add new property timeslot object entirely, sort that. unfortunately, date portion of time stamp appears carried on still.

angular controller:

angular.foreach($scope.timeslots, function (timeslot, index) {     timeslot.begintimedisplay = moment(timeslot.begintime).format("hh:mm a");     timeslot.endtimedisplay = moment(timeslot.endtime).format("hh:mm a"); }); 

angular template:

<tr ng-repeat="timeslot in timeslots | orderby: 'begintimedisplay'"> 

why not calculate timestamp yourself:

var date = new date; date.settime(timeslot.begintime);  var seconds = date.getseconds(); var minutes = date.getminutes(); var hours = date.gethours();  timeslot.ts = hours*60*60+minutes*60+seconds; 

then <tr ng-repeat="timeslot in timeslots | orderby: 'ts'">


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -