如何在Angularjs中降序datetime ng-repeat进行排序?

时间:2016-12-27 18:30:08

标签: angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

我想按降序日期对数据进行排序,即27,26,25 ....如何做?

<tbody class="gradeX" ng-repeat="x in Profile | orderBy: x.created_datetime">
  <tr>
    <td>{{x.job_title }}</td>
    <td>{{x.created_datetime | date:'medium' }}</td>
    <td>{{x.updated_datetime | date:'medium' }}</td>
    <td>{{x.status}}</td>
    <td>{{ x.total }}</td>
    <td class="actions"> <a href="" data-toggle="tooltip" title="Show Invoice Details" ng-click="activeinvoicesCtrl.setCurrentJob(x)"><i class="fa fa-server fa-2x" aria-hidden="true"></i></a> </td>
  </tr>
</tbody>

2 个答案:

答案 0 :(得分:0)

 <tbody class="gradeX" ng-repeat="x in Profile | orderBy: 'created_datetime'">
                                        <tr >
                                            <td>{{x.job_title }}</td>
                                            <td>{{x.created_datetime  | date:'medium' }}</td>
                                            <td>{{x.updated_datetime  | date:'medium' }}</td>
                                            <td>{{x.status}}</td>
                                         <td >{{ x.total }}</td>
                                         <td class="actions">
                          <a href="" data-toggle="tooltip" title="Show Invoice Details"  ng-click="activeinvoicesCtrl.setCurrentJob(x)"><i class="fa fa-server fa-2x" aria-hidden="true"></i></a>

                        </td>                                       
                                        </tr>
                                    </tbody>

确保你的created_datetime对象是一个javascript Date()对象,否则你可能会惊讶地发现1 feb在2月1日之前。

答案 1 :(得分:0)

添加一个字符串,其中包含您要查找的属性的名称。 如果是嵌套属性,请使用。连接字符串,例如&#39; item.created_datetime&#39;

<tbody class="gradeX" ng-repeat="x in Profile | orderBy: '-created_datetime'">