Skip to content

Commit 38844a9

Browse files
author
skozlov
committed
Commit dist dataGrid.js
1 parent 69eb586 commit 38844a9

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

dist/dataGrid.js

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@
5555
}
5656
});
5757

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+
}
6264
$scope.paginationOptions.currentPage = 1;
6365
$scope.reloadGrid();
6466
};
@@ -107,7 +109,7 @@
107109
//custom filters
108110
$scope.filters.forEach(function (filter) {
109111
var urlName = filter.model,
110-
value = $scope.$eval(urlName);
112+
value = filter.isInScope ? $scope.$eval(urlName) : $scope.$parent.$eval(urlName);
111113

112114
if (filter.disableUrl) {
113115
needApplyFilters = true;
@@ -173,8 +175,13 @@
173175
}
174176

175177
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+
}
178185
}
179186
});
180187

@@ -212,10 +219,14 @@
212219

213220
function getData() {
214221
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+
}
219230
// -> to promise
220231
//$scope._gridOptions.getData('?' + url).then(function (data, totalItems) {
221232
// $scope.filtered = data;
@@ -260,7 +271,7 @@
260271
$scope.filters.forEach(function (filter) {
261272
var predicate = filter.filterBy,
262273
urlName = filter.model,
263-
value = $scope.$eval(urlName),
274+
value = filter.isInScope ? $scope.$eval(urlName) : $scope.$parent.$eval(urlName),
264275
type = filter.filterType;
265276
if ($scope.customFilters[urlName]) {
266277
$scope.filtered = $scope.customFilters[urlName]($scope.filtered, value, predicate);
@@ -302,7 +313,7 @@
302313

303314
angular.forEach(angular.element(document.querySelectorAll('[filter-by]')), function (filter) {
304315
var element = angular.element(filter),
305-
isInScope = directiveElement.find(element).length > 0,
316+
isInScope = $element.find(element).length > 0,
306317
predicate = element.attr('filter-by'),
307318
filterType = element.attr('filter-type') || '',
308319
urlName = element.attr('ng-model'),
@@ -329,7 +340,7 @@
329340
element.attr('ng-change', 'filter()');
330341
//$compile(element)($scope);
331342
}
332-
$compile(element)($scope);
343+
//$compile(element)($scope);
333344
filters.push({
334345
model: urlName,
335346
isInScope: isInScope,

dist/dataGrid.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)