1

Please look at following code, it is working fine for order-by date but as a string.

<tr ng-repeat="i in nonDeletedItems(this) | orderBy: 'data.FollowUpDate'" 
mp-managed-list-item item="i" ready="isReady" item-template="rowTemplate" 
item-template-html="rowTemplateHtml" item-list-type="listType"></tr>

I need to order by date as date.

2
  • 1
    It would only work if data.FollowUpDate has date object.. Commented Mar 30, 2016 at 9:55
  • data.FollowUpDate is string like "01/01/2016" . can we convert it into date ? Commented Mar 30, 2016 at 9:57

1 Answer 1

1

Use custom filter to achive this.

myApp.filter('sortByDate', function () {
    return function (events) {
        if (!events) {
            return true;
        }
        if (events.length == 0) {
            return events;
        }
        for(var i=0; i<events.length; i++){
            for(var j=i+1; j<events.length; j++){
                var t1 = new Date(events[i].updatedTime).getTime()
                var t2 = new Date(events[j].updatedTime).getTime()
                if(t1 > t2){
                    var temp = events[i]
                    events[i] = events[j]
                    events[j] = temp;
                }
            }
        }
        return events;
    };
})

HTML

<tr ng-repeat="i in nonDeletedItems(this) | sortByDate" 
  mp-managed-list-item item="i" ready="isReady" item-template="rowTemplate" 
  item-template-html="rowTemplateHtml" item-list-type="listType">
</tr>
Sign up to request clarification or add additional context in comments.

2 Comments

yes, it is working fine but got descending mode. can you please change it with ascending mode ?
Updated for ascending order.

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.