Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function () {
  2.     'use strict';
  3.  
  4.     angular
  5.             .module('...')
  6.             .directive('sortAttr', function () {
  7.                 return {
  8.                     require: '^^sort',
  9.                     restrict: 'A',
  10.                     scope: {},
  11.                     link: addSortableArrows
  12.                 };
  13.             });
  14.  
  15.     function addSortableArrows(scope, element, attr, sortCollectionController) {
  16.         var SORT_ASC = 'sort-asc';
  17.         var SORT_DESC = 'sort-desc';
  18.         var CLICKABLE = 'clickable';
  19.         var SORTABLE = 'sortable';
  20.         var CLICK_EVENT = 'click';
  21.        
  22.         scope.reverse = false;
  23.  
  24.         element.addClass(CLICKABLE);
  25.         element.addClass(SORTABLE);
  26.  
  27.         element.bind(CLICK_EVENT, function (e) {
  28.             var allHeaders = element.parent().children();
  29.             allHeaders.removeClass(SORT_ASC);
  30.             allHeaders.removeClass(SORT_DESC);
  31.             if (scope.reverse) {
  32.                 element.removeClass(SORT_ASC);
  33.                 element.addClass(SORT_DESC);
  34.             } else {
  35.                 element.removeClass(SORT_DESC);
  36.                 element.addClass(SORT_ASC);
  37.             }
  38.             sortCollectionController.sortBy(attr.sortAttr, scope.reverse);
  39.             scope.reverse = !scope.reverse;
  40.         });
  41.     }
  42. })();
  43.  
  44.  
  45. (function () {
  46.     'use strict';
  47.  
  48.     angular
  49.             .module('LynxMethod')
  50.             .controller('SortController', [
  51.                 '$scope',
  52.                 controller
  53.             ]);
  54.  
  55.     function controller($scope) {
  56.  
  57.         var vm = this;
  58.         vm.sortBy = sortBy;
  59.  
  60.         function sortBy(attribute, reverse) {
  61.             vm.by = attribute;
  62.             vm.reverse = reverse;
  63.             $scope.$apply();
  64.         }
  65.  
  66.     }
  67. })();
  68.  
  69. (function () {
  70.     'use strict';
  71.  
  72.     angular
  73.             .module('LynxMethod')
  74.             .directive('sort', function () {
  75.                 return {
  76.                     restrict: 'A',
  77.                     scope: {
  78.                         by: '=',
  79.                         reverse: '='
  80.                     },
  81.                     controller: 'SortController',
  82.                     controllerAs: 'vm',
  83.                     bindToController: true
  84.                 };
  85.             });
  86. })();
  87.  
  88.  
  89. <table class="table table-hover animated fadeIn" sort by="vm.sortAttribute" reverse="vm.sortReverse">
  90.     <thead>
  91.         <tr>
  92.             <th ng-if="vm.showPpe" sort-attr="number">PPE</th>
  93.             <th sort-attr="number">Numer</th>
  94.             <th sort-attr="startDate">Od</th>
  95. ...
  96.  
  97.  
  98. /* TABLE SORTABLE */
  99. th.sortable {
  100.     -webkit-user-select: none;
  101.     -khtml-user-select: none;
  102.     -moz-user-select: none;
  103.     -o-user-select: none;
  104.     user-select: none;
  105.     cursor: pointer;
  106. }
  107.  
  108. table .sortable:after{
  109.     content:"";
  110.     float:right;
  111.     margin-top:7px;
  112.     visibility:hidden;
  113.     border-left:4px solid transparent;
  114.     border-right:4px solid transparent;
  115.  
  116.     border-top:none;
  117.     border-bottom:4px solid #000;
  118. }
  119.  
  120. table .sort-desc:after{
  121.     border-top:4px solid #000;
  122.     border-bottom:none;
  123. }
  124.  
  125. table .sort-asc,table .sort-desc{
  126.     background-color:rgba(50, 200, 222, 0.25);
  127. }
  128.  
  129. table .sortable:hover:after, table .sort-asc:after, table .sort-desc:after {
  130.     visibility:visible;
  131. }
  132.  
  133. .col-centered{
  134.     float: none;
  135.     margin: 0 auto;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement