如何:在AngularJS中进行多列排序,同时维护';始终领先';记录?
我有一个简单的表,我正在对其进行排序,我希望能够按两列中的一列(日期或“has attachment”)进行排序,但要在表的顶部保留特定的记录(固定的记录),然后对后面的行进行排序 Html代码如何:在AngularJS中进行多列排序,同时维护';始终领先';记录?,angularjs,sorting,Angularjs,Sorting,我有一个简单的表,我正在对其进行排序,我希望能够按两列中的一列(日期或“has attachment”)进行排序,但要在表的顶部保留特定的记录(固定的记录),然后对后面的行进行排序 Html代码 <table class="table table-striped table-bordered table-hover"> <thead> <tr> <th style="width: 50px" class="
<table class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th style="width: 50px" class="centered">
<div class="icon-refresh clickable" ng-click="loadNotes()"></div>
</th>
<th class="clickable colored_text" style="width: 50px" ng-click="sort('LastModified')">Last Modified</th>
<th class="clickable colored_text" style="width: 50px" ng-click="sort('HasAttachment')">Attachment</th>
<th>Note</th>
</tr>
</thead>
<tr ng-show="notesLoaded == true && notes.length == 0">
<td colspan="3">No notes found.</td>
</tr>
<tr ng-repeat="note in notes | filter: myFilterNotes | orderBy: noteSortOrder: noteSortDirection | startAt: (currentPage-1)*pageSize | limitTo :pageSize " ng-class="{'pinned': note.Pinned}">
<td class="span1"><button class="btn btn-inverse" ng-click="editNote(note.Id)" ng-show="(note.CreatedBy == history.currentUserId && note.TypeId === 0) || (history.canEditNotes && note.TypeId === 0)">Edit</button></td>
<td>{{note.LastModified | date:'MM/dd/yyyy h:mm a'}}</td>
<td class="centered">
<span ng-if="note.HasAttachment">
<a href ng-click="downloadAttachment(note)"><i class="icon-paper-clip icon-1point5x" title="{{note.NoteFileName}}"></i></a>
</span>
</td>
<td class="forceWordWrap">
<div class="span11">
<span ng-show="note.TypeId === 1">(Lead Note) </span>
<span ng-if="note.IsValidHtml" ng-bind-html="note.Note"></span>
<span ng-if="!note.IsValidHtml" ng-repeat="line in (note.Note | newlines) track by $index">
{{line}}<br/>
</span>
<span style="color: #bbb; font-size: 85%; font-weight: normal">
<p style="margin: 0;">-- created by {{(note.CreatedByName.length > 0) ? note.CreatedByName : "Unknown"}} on {{::note.CreatedDate | date:'MM/dd/yyyy h:mm a' }}</p>
<span ng-show="note.LastModifiedBy.length > 0">
<p style="margin: 0;">-- last modified by {{::note.LastModifiedBy}}</p>
</span>
</span>
</div>
<span class="span1" ng-show="note.Pinned" style="color: rgb(255, 0, 0);">
<i class="icon-pushpin icon-1point5x"></i>
</span>
</td>
</tr>
</table>
最初的多列排序工作正常,但当我单击其中一个标题时,它会以一些不可靠的方式对“固定”的内容进行排序。(以下截图)
这是伟大的工作!
这个,不多。就好像它完全按照我想要的方式排序,然后把整个事情颠倒过来!(grr)
理想情况下,这就是我想要的!
解决了这个问题。我从ng重复中删除了排序顺序:
<tr ng-repeat="note in notes | filter: myFilterNotes | orderBy: noteSortOrder: true | startAt: (currentPage-1)*pageSize | limitTo :pageSize " ng-class="{'pinned': note.Pinned}">
tr ng repeat=“filteredNotes中的注释”--将您所有的神奇逻辑都放到javascript中。我已经做到了。我上面提到的排序方法就是我用来进行排序的方法。我只需要知道如何调整它来做我要求它做的事情。
<tr ng-repeat="note in notes | filter: myFilterNotes | orderBy: noteSortOrder: true | startAt: (currentPage-1)*pageSize | limitTo :pageSize " ng-class="{'pinned': note.Pinned}">
$scope.sort = function (column) {
var sortDir = $scope.noteSortDirection;
var revSortDir = !sortDir;
var sortColumnWithDirection = revSortDir !== true
? "-" + column
: column;
var newSortOrder = ["Pinned", sortColumnWithDirection];
$scope.noteSortDirection = !$scope.noteSortDirection;
$scope.noteSortOrder = newSortOrder;
};