Created
March 13, 2015 21:37
-
-
Save menacestudio/b26859a53ff279e30a98 to your computer and use it in GitHub Desktop.
An AngularJS directive to add sorting capability to table headers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sortableGrid.$inject = []; | |
function sortableGrid() { | |
return <ng.IDirective>{ | |
restrict: 'A', | |
scope: { | |
order: '=', | |
by: '=', | |
reverse: '=' | |
}, | |
transclude: true, | |
template: '<a ng-click="sort()">' + | |
'<span ng-transclude></span>' + | |
'</a> <i class="glyphicon" ng-class="{\'fa fa-sort-asc\' : order===by && !reverse, \'fa fa-sort-desc\' : order===by && reverse}"></i>', | |
link: link | |
} | |
function link($scope, $element, $attrs) { | |
$scope.sort = function () { | |
if ($scope.order === $scope.by) { | |
$scope.reverse = !$scope.reverse | |
} else { | |
$scope.by = $scope.order; | |
$scope.reverse = false; | |
} | |
} | |
} | |
} | |
angular.module('app').directive('sortableGrid', sortableGrid); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment