|
55 | 55 | } |
56 | 56 | }); |
57 | 57 |
|
58 | | - $scope.sort = function (predicate) { |
59 | | - var direction = $scope.sortOptions.predicate === predicate && $scope.sortOptions.direction === 'desc' ? 'asc' : 'desc'; |
60 | | - $scope.sortOptions.predicate = predicate; |
61 | | - $scope.sortOptions.direction = direction; |
| 58 | + $scope.sort = function (predicate, isDefaultSort) { |
| 59 | + if (!isDefaultSort) { |
| 60 | + var direction = $scope.sortOptions.predicate === predicate && $scope.sortOptions.direction === 'desc' ? 'asc' : 'desc'; |
| 61 | + $scope.sortOptions.direction = direction; |
| 62 | + $scope.sortOptions.predicate = predicate; |
| 63 | + } |
62 | 64 | $scope.paginationOptions.currentPage = 1; |
63 | 65 | $scope.reloadGrid(); |
64 | 66 | }; |
|
107 | 109 | //custom filters |
108 | 110 | $scope.filters.forEach(function (filter) { |
109 | 111 | var urlName = filter.model, |
110 | | - value = $scope.$eval(urlName); |
| 112 | + value = filter.isInScope ? $scope.$eval(urlName) : $scope.$parent.$eval(urlName); |
111 | 113 |
|
112 | 114 | if (filter.disableUrl) { |
113 | 115 | needApplyFilters = true; |
|
173 | 175 | } |
174 | 176 |
|
175 | 177 | if (value) { |
176 | | - $scope.__evaltmp = value; |
177 | | - $scope.$eval(urlName + '=__evaltmp'); |
| 178 | + if (filter.isInScope) { |
| 179 | + $scope.__evaltmp = value; |
| 180 | + $scope.$eval(urlName + '=__evaltmp'); |
| 181 | + } else { |
| 182 | + $scope.$parent.__evaltmp = value; |
| 183 | + $scope.$parent.$eval(urlName + '=__evaltmp'); |
| 184 | + } |
178 | 185 | } |
179 | 186 | }); |
180 | 187 |
|
|
212 | 219 |
|
213 | 220 | function getData() { |
214 | 221 | var url = $location.path().slice(1); |
215 | | - $scope._gridOptions.getData('?' + url, function (data, totalItems) { |
216 | | - $scope.filtered = data; |
217 | | - $scope.paginationOptions.totalItems = totalItems; |
218 | | - }); |
| 222 | + if (!url && $scope.sortOptions.predicate) { |
| 223 | + $scope.sort($scope.sortOptions.predicate, true); |
| 224 | + } else { |
| 225 | + $scope._gridOptions.getData('?' + url, function (data, totalItems) { |
| 226 | + $scope.filtered = data; |
| 227 | + $scope.paginationOptions.totalItems = totalItems; |
| 228 | + }); |
| 229 | + } |
219 | 230 | // -> to promise |
220 | 231 | //$scope._gridOptions.getData('?' + url).then(function (data, totalItems) { |
221 | 232 | // $scope.filtered = data; |
|
260 | 271 | $scope.filters.forEach(function (filter) { |
261 | 272 | var predicate = filter.filterBy, |
262 | 273 | urlName = filter.model, |
263 | | - value = $scope.$eval(urlName), |
| 274 | + value = filter.isInScope ? $scope.$eval(urlName) : $scope.$parent.$eval(urlName), |
264 | 275 | type = filter.filterType; |
265 | 276 | if ($scope.customFilters[urlName]) { |
266 | 277 | $scope.filtered = $scope.customFilters[urlName]($scope.filtered, value, predicate); |
|
302 | 313 |
|
303 | 314 | angular.forEach(angular.element(document.querySelectorAll('[filter-by]')), function (filter) { |
304 | 315 | var element = angular.element(filter), |
305 | | - isInScope = directiveElement.find(element).length > 0, |
| 316 | + isInScope = $element.find(element).length > 0, |
306 | 317 | predicate = element.attr('filter-by'), |
307 | 318 | filterType = element.attr('filter-type') || '', |
308 | 319 | urlName = element.attr('ng-model'), |
|
329 | 340 | element.attr('ng-change', 'filter()'); |
330 | 341 | //$compile(element)($scope); |
331 | 342 | } |
332 | | - $compile(element)($scope); |
| 343 | + //$compile(element)($scope); |
333 | 344 | filters.push({ |
334 | 345 | model: urlName, |
335 | 346 | isInScope: isInScope, |
|
0 commit comments