您可以使用動態類是基於什麼領域的網格目前按排序。這可以在Angular Documentation的修改示例中看到。
變形示例中使用的類和清除按鈕:http://plnkr.co/edit/b0wlqLf3QQx0T5ccdZrP?p=preview
HTML:
<div ng-app="orderByExample" ng-controller="ExampleController">
<pre>Sorting predicate = {{predicate}}; reverse = {{reverse}}</pre>
<button ng-click="clear()">Clear Sort</button>
<table class="friend">
<tr>
<th>
<button ng-click="order('name')">
Name <i class="sort-icon fa" ng-class="orderClass('name')"></i>
</button
</th>
<th>
<button ng-click="order('phone')">
Phone Number <i class="sort-icon fa" ng-class="orderClass('phone')"></i>
</button>
</th>
<th>
<button ng-click="order('age')">
Age
<i class="sort-icon fa" ng-class="orderClass('age')"></i>
</button>
</th>
</tr>
<tr ng-repeat="friend in friends">
<td>{{friend.name}}</td>
<td>{{friend.phone}}</td>
<td>{{friend.age}}</td>
</tr>
</table>
</div>
JS:
angular.module('orderByExample', [])
.controller('ExampleController', ['$scope', '$filter', function($scope, $filter) {
var orderBy = $filter('orderBy');
$scope.friends = [
{ name: 'John', phone: '555-1212', age: 10 },
{ name: 'Mary', phone: '555-9876', age: 19 },
{ name: 'Mike', phone: '555-4321', age: 21 },
{ name: 'Adam', phone: '555-5678', age: 35 },
{ name: 'Julie', phone: '555-8765', age: 29 }
];
$scope.order = function(predicate) {
$scope.predicate = predicate;
$scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;
$scope.friends = orderBy($scope.friends, predicate, $scope.reverse);
};
$scope.orderClass = function(predicate){
return $scope.predicate === predicate ? ('fa-sort' + ($scope.reverse ? '-desc' : '-asc')) : 'fa-sort';
};
$scope.clear = function(){
$scope.predicate = '';
};
$scope.order('age', true);
}]);
您已經標記了'angularjs',但這裏的代碼是'jQuery'。請在線分享您的代碼。 – Shashank
必須刪除主動上升/下降類的點擊清除按鈕角js – John