【发布时间】:2014-06-08 21:28:44
【问题描述】:
我有一个表,我在其中使用大多数 AngularJS 教程中的 doSort() 示例按列对数据进行排序。但是,由于我用 doSort() 用完了 orderBy,我不知道如何进行默认排序。
我尝试堆叠 orderBy(就像您可以使用过滤器一样),但默认值不起作用。
这是我的桌子,但 orderBy:dueDate 被忽略了 --
<table id="tblProjects" class="tblLanding" ng-hide="projectManagerClose">
<tr class="landing_header_row">
<th style="width:7%;" data-ng-click="doProjSort('Priority')">Priority</th>
<th style="width:3%;" data-ng-click="doProjSort('Task_Id')">ID</th>
<th style="width:17%;" data-ng-click="doProjSort('Description')">Description</th>
<th style="width:10%;" data-ng-click="doProjSort('Status')">Status</th>
<th style="width:15%;" data-ng-click="doProjSort('Division')">Division</th>
<th style="width:12%;" data-ng-click="doProjSort('Requestor')">Requestor</th>
<th style="width:12%;" data-ng-click="doProjSort('ProjMan')">Project Manager</th>
<th style="width:12%;" data-ng-click="doProjSort('AssignedTo')">Assigned To</th>
<th style="width:12%;" data-ng-click="doProjSort('DueDate')">Due Date</th>
</tr>
<tr class="landing_data_row" data-ng-repeat="project in open_projects |
filter: pmProjectsFilter | filter: statusFilter |
orderBy: DueDate | orderBy:sortProjBy:reverse">
<td><div class='sprite indic-{{project.Priority}} centered'></div></td>
<td style="text-align:center;">{{project.Task_Id}}</td>
<td><a href="#">{{project.Description}}</a></td>
<td>{{project.Status}}</td>
<td>{{project.Division}}</td>
<td>{{project.Requestor}}</td>
<td>{{project.ProjMan}}</td>
<td>{{project.AssignedTo}}</td>
<td>{{project.DueDate | date : 'MMM dd, yyyy'}}</td>
</tr>
</table>
【问题讨论】:
-
该数组适用于其中两个字段,但在我使用 | 时会隐藏所有记录orderBy: 'DueDate', 'sortProjBy:reverse' |
-
我会考虑使用您的排序函数 (doProjSort) 操作的 sortString 类型“模型”。然后使用 sortString 作为 orderBy 的参数。字符串应该类似于“+column1, -column2”。
标签: angularjs