2017-12-14 1 views
-1

나는이 코드 조각이 말 : 표시됩니다 모든 것이 연대순 날짜를 오름차순으로 정렬 할 수 있도록자바 스크립트 날짜 기준으로 정렬하는 방법/각도 {{}}

<tr ng-repeat-start="caseHistory in vm.caseHistory"> 
      <td >{{caseHistory.date | date:"dd-MMM-yyyy h:mm a"}}</td> 
      <td >{{caseHistory.description}}</td> 
      <td >{{caseHistory.performedByUser.firstName}} {{caseHistory.performedByUser.lastName}} ({{caseHistory.performedByUser.externalAssociateId}})</td> 
      <td> 
       <span ng-show="vm.showCreateCaseComments(caseHistory.eventType,caseHistory.comments)"> 
        <a ng-if="caseHistory.expanded" class="removeTextDecoration headerPointer" ng-click="caseHistory.expanded = false"> -Collapse</a> 
        <a ng-if="!caseHistory.expanded" class="removeTextDecoration headerPointer" ng-click="caseHistory.expanded = true"> +Expand</a> 
       </span> 
      </td> 
     </tr> 

내가 그것을 좋아하는 것입니다.

모든 결과를 날짜순으로 정렬하려면 무엇을 {{caseHistory.date | date:"dd-MMM-yyyy h:mm a"}}에 추가해야합니까?

+1

https://docs.angularjs.org/api/ng/filter/orderBy#examples –

답변

0

당신은 여기에 파이프를 추가해야합니다 : 당신은 또한 추가 할 수

<tr ng-repeat-start="caseHistory in vm.caseHistory | orderBy:'caseHistory.date'"> 

- 하강 대 상승 지정하는 기호를 ''. https://docs.angularjs.org/api/ng/filter/orderBy

0

사용 orderBy 필터 및 따르면 필드 이름

<tr ng-repeat-start="caseHistory in vm.caseHistory | orderBy: '-date'"> 
0

앞에 -

<tr ng-repeat-start="caseHistory in vm.caseHistory | orderBy: 'date':true"> 

하강에 대한 역방향 옵션을 추가 또는 추가

문서는 여기에서 찾을 수 있습니다 Angular 공식 튜토리얼 파이프 또는 필터가 없어야합니다. 정렬 목적으로 sed.

Main.prototype = { 

sort: function(item) { 
    if (this.predicate == 'date') { 
     return new Date(item.date); 
    } 
    return item[this.predicate]; 
}, 

sortBy: function(field) { 
    if (this.predicate != field) { 
     this.predicate = field; 
     this.reverse = false; 
    } else { 
     this.reverse = !this.reverse; 
    } 
}, 

reverse: false}; 

는 참조 용으로 jsfiddle 다음을 참조하십시오 :

당신 같은이 작업을 수행하려면 사용자 정의 메소드를 작성할 수 있습니다.