角度を使用して列を並べ替えようとしています。angularチュートリアルのコードが機能するようになりました。
今、1行を常に一番上に置くのに苦労しています。たとえば、mainContact という 1 つの列があります。この値を true に設定できるのは 1 人だけです。mainContact が true の人は常にテーブルの一番上の行に留まり、他の人は並べ替えで変化します。正直なところ、これを行う方法についてのアイデアが少し失われています。
私がこれまでに持っているものを示すためにこれをまとめました: http://jsfiddle.net/Beastwood/m44fy1j5/
<div ng-controller="ExampleController">
<pre>Sorting predicate = {{predicate}}; reverse = {{reverse}}</pre>
<table class="friend">
<tr>
<th><a href="" ng-click="predicate = 'name'; reverse=false">Name</a></th>
<th><a href="" ng-click="predicate = 'phone'; reverse=!reverse">Phone Number</a></th>
<th><a href="" ng-click="predicate = 'age'; reverse=!reverse">Age</a></th>
<th>MAIN CONTACT</th>
</tr>
<tr ng-repeat="friend in friends | orderBy:predicate:reverse">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
<td>{{friend.age}}</td>
<td>{{friend.mainContact}}</td>
</tr>
</table>
</div>
JS ファイル
var myApp = angular.module('myApp', [])
.controller('ExampleController', ['$scope', function($scope) {
$scope.friends =
[{name:'John', phone:'555-1212', age:10, mainContact:true},
{name:'Mary', phone:'555-9876', age:19, mainContact:false},
{name:'Mike', phone:'555-4321', age:21, mainContact:false},
{name:'Adam', phone:'555-5678', age:35, mainContact:false},
{name:'Julie', phone:'555-8765', age:29, mainContact:false}];
$scope.predicate = '-age';
}]);