Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions demo/bootstrap/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ <h4>Additional Demos</h4>
class="form-control"
uib-datepicker-popup="dd/MM/yyyy"
placeholder="DD/MM/YYYY"
min-date="dateFrom"
max-date="dateTo"
close-text="Close"
ng-model="dateFrom"
Expand Down Expand Up @@ -117,7 +116,7 @@ <h4>Additional Demos</h4>
</div>
</div>
<div ng-show="dateTo || dateFrom" class="buttons-right">
<a href="" ng-click="dateTo = ''; dateFrom = ''; reloadGrid();">Clear Dates</a>
<a href="" ng-click="dateTo = ''; dateFrom = ''; gridActions.refresh();">Clear Dates</a>
</div>
</div>
</div>
Expand Down
6 changes: 4 additions & 2 deletions demo/bootstrap/multiple.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ <h2>First Grid</h2>
ng-change="gridActions1.filter()"
ng-model="name"
filter-by="name"
grid-id="grid1"
filter-type="text">
</div>
</div>
Expand Down Expand Up @@ -130,7 +131,8 @@ <h2>Second Grid</h2>
<input type="text" class="form-control order-search-box"
placeholder="Enter User Name"
ng-change="gridActions2.filter()"
ng-model="name"
ng-model="name2"
grid-id="grid2"
filter-by="name"
filter-type="text">
</div>
Expand Down Expand Up @@ -224,7 +226,7 @@ <h2>Second Grid</h2>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-aria.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-messages.min.js"></script>
<script src="../../dist/pagination.min.js"></script>
<script src="../../dist/dataGrid.min.js"></script>
<script src="../../dist/dataGrid.js"></script>
<script src="js/multipleApp.js"></script>

</html>
73 changes: 30 additions & 43 deletions dist/dataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
})
.controller('gridController', ['$scope', '$element', '$filter', '$location', 'filtersFactory', function ($scope, $element, $filter, $location, filtersFactory) {
// values by default
$scope._gridOptions = deepFind($scope, $element.attr('grid-options'));
$scope._gridActions = deepFind($scope, $element.attr('grid-actions'));
$scope._gridOptions = $scope.$eval($element.attr('grid-options'));
$scope._gridActions = $scope.$eval($element.attr('grid-actions'));
$scope.serverPagination = $element.attr('server-pagination') === 'true';
$scope.getDataDelay = $element.attr('get-delay') || 350;

if (!$scope._gridActions) {
$scope.$parent[$element.attr('grid-actions')] = {};
$scope._gridActions = $scope.$parent[$element.attr('grid-actions')];
$scope.$parent.$eval($element.attr('grid-actions') + '= {}');
$scope._gridActions = $scope.$parent.$eval($element.attr('grid-actions'));
}

$scope.filtered = angular.copy($scope._gridOptions.data);
$scope._gridOptions.grid = $scope;

$scope.filtered = $scope._gridOptions.data.slice();
$scope.paginationOptions = $scope._gridOptions.pagination ? angular.copy($scope._gridOptions.pagination) : {};
$scope.defaultsPaginationOptions = {
itemsPerPage: $scope.paginationOptions.itemsPerPage || '10',
Expand Down Expand Up @@ -105,7 +107,7 @@
//custom filters
$scope.filters.forEach(function (filter) {
var urlName = filter.model,
value = $scope[urlName];
value = $scope.$eval(urlName);

if (filter.disableUrl) {
needApplyFilters = true;
Expand Down Expand Up @@ -152,29 +154,35 @@
//custom filters
$scope.filters.forEach(function (filter) {
var urlName = filter.model,
value = customParams[urlName],
scope = $scope;
value = customParams[urlName];

if (filter.disableUrl) {
return;
}

if (~filter.filterType.toLowerCase().indexOf('date') && value) {
scope[urlName] = new Date(value);
//datepicker-specific
if (~filter.filterType.toLowerCase().indexOf('date')) {
$scope.$parent.__evaltmp = value ? new Date(value) : null;
$scope.$parent.$eval(urlName + '=__evaltmp');
return;
}


if (filter.filterType === 'select' && !value) {
value = "";
value = '';
}

scope[urlName] = value;
if (value) {
$scope.__evaltmp = value;
$scope.$eval(urlName + '=__evaltmp');
}
});

if (!$scope.serverPagination) {
applyCustomFilters();
}


//pagination options
$scope.paginationOptions.itemsPerPage = $scope.defaultsPaginationOptions.itemsPerPage;
$scope.paginationOptions.currentPage = $scope.defaultsPaginationOptions.currentPage;
Expand Down Expand Up @@ -252,7 +260,7 @@
$scope.filters.forEach(function (filter) {
var predicate = filter.filterBy,
urlName = filter.model,
value = $scope[urlName],
value = $scope.$eval(urlName),
type = filter.filterType;
if ($scope.customFilters[urlName]) {
$scope.filtered = $scope.customFilters[urlName]($scope.filtered, value, predicate);
Expand All @@ -265,24 +273,19 @@
});
}
}])
.directive('gridData', ['$compile', '$animate', function ($compile, $animate) {
.directive('gridData', ['$compile', '$animate', function ($compile) {
return {
restrict: 'EA',
transclude: true,
replace: true,
scope: true,
controller: 'gridController',
link: function ($scope, $element, attrs, controller, $transclude) {
link: function ($scope, $element, attrs) {
var sorting = [],
filters = [],
rows = [],
childScope = $scope.$new(),
directiveElement = $element.parent(),
gridId = attrs.id,
serverPagination = attrs.serverPagination === 'true';

$transclude($scope, function (clone) {
$animate.enter(clone, $element);
});

angular.forEach(angular.element(directiveElement[0].querySelectorAll('[sortable]')), function (sortable) {
var element = angular.element(sortable),
Expand All @@ -292,7 +295,7 @@
predicate + "' && sortOptions.direction === 'asc', 'sort-descent' : sortOptions.predicate === '" +
predicate + "' && sortOptions.direction === 'desc'}");
element.attr('ng-click', "sort('" + predicate + "')");
$compile(element)(childScope);
$compile(element)($scope);
});

angular.forEach(angular.element(document.querySelectorAll('[filter-by]')), function (filter) {
Expand All @@ -309,20 +312,18 @@

if (filterType !== 'select') {
} else {
$scope[urlName + 'Options'] = generateOptions(deepFind($scope, $element.attr('grid-options') + '.data'), predicate);
$scope[urlName + 'Options'] = generateOptions($scope.$eval($element.attr('grid-options') + '.data'), predicate);
}

if (~filterType.indexOf('date') && !element.attr('ng-focus')
&& !element.attr('ng-blur')) {
element.attr('ng-focus', "filter('{" + urlName + " : " + "this." + urlName + "}')");
element.attr('ng-blur', "filter('{" + urlName + " : " + "this." + urlName + "}')");
$compile(element)($scope);
}
if (!urlName) {
urlName = predicate;
element.attr('ng-model', predicate);
element.attr('ng-change', 'filter()');
$compile(element)($scope);
}

filters.push({
Expand All @@ -332,6 +333,8 @@
filterType: filterType,
disableUrl: disableUrl
});

$compile(element)($scope);
});

angular.forEach(angular.element(directiveElement[0].querySelectorAll('[grid-item]')), function (row) {
Expand All @@ -342,7 +345,7 @@
} else {
element.attr('ng-repeat', "item in filtered | startFrom:(paginationOptions.currentPage-1)*paginationOptions.itemsPerPage | limitTo:paginationOptions.itemsPerPage track by $index");
}
$compile(element)(childScope);
$compile(element)($scope);
});

$scope.sorting = sorting;
Expand All @@ -360,7 +363,7 @@

function textFilter(items, value, predicate) {
return items.filter(function (item) {
return value && item[predicate] ? ~(item[predicate] + '').toLowerCase().indexOf(value.toLowerCase()) : true;
return value && item[predicate] ? ~(item[predicate] + '').toLowerCase().indexOf((value + '').toLowerCase()) : true;
});
}

Expand Down Expand Up @@ -406,22 +409,6 @@
}
});

function deepFind(obj, path) {
var paths = path.split('.'),
current = obj,
i;

for (i = 0; i < paths.length; ++i) {
if (current[paths[i]] == undefined) {
return undefined;
} else {
current = current[paths[i]];
}
}
return current;
}


function generateOptions(values, predicate) {
var array = [];
if (values) {
Expand Down
Loading