Last active
November 11, 2015 15:46
-
-
Save geraldhumphries/bd7190387ca711f1bb20 to your computer and use it in GitHub Desktop.
sort directive
This file contains 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
<tr jh-sort="predicate" ascending="reverse" callback="loadAll"> | |
<th jh-sort-by="id" translate="global.field.id">ID</th> | |
<th jh-sort-by="testField" translate="jhipsterApp.test123.testField">TestField</th> | |
<th jh-sort-by="point.id" translate="jhipsterApp.test123.point">point</th> | |
<th jh-sort-by="address.id" translate="jhipsterApp.test123.address">address</th> | |
<th></th> | |
</tr> |
This file contains 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
'use strict'; | |
angular.module('jhipsterApp') | |
.directive('jhSort', function () { | |
return { | |
restrict: 'A', | |
scope: { | |
predicate: '=jhSort', | |
ascending: '=', | |
callback: '&' | |
}, | |
controller: ['$scope', function ($scope) { | |
this.sort = function (field) { | |
if (field !== $scope.predicate) { | |
$scope.ascending = true; | |
} else { | |
$scope.ascending = !$scope.ascending; | |
} | |
$scope.predicate = field; | |
$scope.$apply(); | |
$scope.callback(); | |
} | |
}] | |
} | |
}).directive('jhSortBy', function () { | |
return { | |
restrict: 'A', | |
scope: false, | |
require: '^jhSort', | |
link: function (scope, element, attrs, parentCtrl) { | |
element.bind('click', function () { | |
parentCtrl.sort(attrs.jhSortBy); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jhSort
andjhSortBy
so that its in line for our future plugin lib roadmapAny way the directive def looks better than current logic so we can go ahead and improve on the way