Every line of 'angular 2 sort' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
98 function sortOn(array, supplier) { 99 return array.sort(function(a, b) { 100 if (supplier(a) < supplier(b)) { 101 return -1; 102 } else if (supplier(a) > supplier(b)) { 103 return 1; 104 } 105 return 0; 106 }); 107 }
70 sortDataBy(key: string | any) { 71 key = key.split('.'); 72 73 this.dataSource.sort((a: any, b: any) => { 74 let i = 0; 75 while (i < key.length) { 76 a = a[key[i]]; 77 b = b[key[i]]; 78 i++; 79 } 80 81 if (a < b) { 82 this.renderer.setAttribute(this.el.nativeElement, 'aria-sort', 'ascending'); 83 this.renderer.setAttribute( 84 this.el.nativeElement, 85 'aria-label', 86 `${key}: activate to sort column descending` 87 ); 88 this.order = SortDirection.ASC; 89 90 return this.sortedInto ? 1 : -1; 91 } else if (a > b) { 92 this.renderer.setAttribute(this.el.nativeElement, 'aria-sort', 'descending'); 93 this.renderer.setAttribute( 94 this.el.nativeElement, 95 'aria-label', 96 `${key}: activate to sort column ascending` 97 ); 98 this.order = SortDirection.DESC; 99 100 return this.sortedInto ? -1 : 1; 101 } else if (a == null || b == null) { 102 this.order = SortDirection.CONST; 103 return 1; 104 } else { 105 this.order = SortDirection.CONST; 106 return 0; 107 } 108 }); 109 110 this.sortedInto = !this.sortedInto; 111 }
119 function Sort(array, index, length, comparer) { 120 sortImpl(array, index, length, JSIL.$WrapIComparer(null, comparer)); 121 }
124 function orderDirectives(element, dynamicDirectives) { 125 let orderedIds = dynamicDirectiveService.sort(dynamicDirectives).map((d) => d._id); 126 let domIds = element.children('[' + DYNAMIC_DIRECTIVE_ID + ']') 127 .map((index, e) => parseInt(angular.element(e).attr(DYNAMIC_DIRECTIVE_ID), 10)) 128 .toArray(); 129 // 99% of the time 130 if (orderedIds.join(',') === domIds.join(',')) { 131 return; 132 } 133 134 for (let i = 0, len = orderedIds.length - 2; i <= len; i++) { 135 let current = orderedIds[i], next = orderedIds[(i + 1)], 136 $current = element.children('[' + DYNAMIC_DIRECTIVE_ID + '=' + current + ']'); 137 if ($current.next().attr(DYNAMIC_DIRECTIVE_ID) !== next) { 138 element.children('[' + DYNAMIC_DIRECTIVE_ID + '=' + next + ']').insertAfter($current); 139 } 140 } 141 }
109 function Sort(array, comparer) { 110 sortImpl(array, 0, array.length, JSIL.$WrapIComparer(null, comparer)); 111 }
147 function sort(sortfield){ 148 if (sortfield == tableCtrl.sortObj.field){ 149 tableCtrl.sortObj.field = sortfield; 150 tableCtrl.sortObj.reverse = !tableCtrl.sortObj.reverse; 151 tableCtrl.sortObj.iconDirection = { 152 "angle down icon": !tableCtrl.sortObj.reverse, 153 "angle up icon": tableCtrl.sortObj.reverse 154 } 155 } 156 else{ 157 tableCtrl.sortObj = initializeSort(sortfield); 158 } 159 tableCtrl.showChunk(tableCtrl.pageNo, tableCtrl.searchText); 160 $scope.$apply(); 161 }