Skip to content

Filter changes #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
Added to from numbers
  • Loading branch information
HuwSy authored Sep 20, 2017
commit 5cd31b1f953f523b85dd8537e93769e51a213f81
40 changes: 36 additions & 4 deletions dist/dataGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@
$scope.filtered = $scope._gridOptions.data.slice();
$scope.paginationOptions = $scope._gridOptions.pagination ? angular.copy($scope._gridOptions.pagination) : {};
$scope.defaultsPaginationOptions = {
itemsPerPage: $scope.paginationOptions.itemsPerPage,
itemsPerPage: $scope.paginationOptions.itemsPerPage || '10',
currentPage: $scope.paginationOptions.currentPage || 1
};
$scope.paginationOptions = angular.copy($scope.defaultsPaginationOptions);
$scope.sortOptions = $scope._gridOptions.sort ? angular.copy($scope._gridOptions.sort) : {};
$scope.customFilters = $scope._gridOptions.customFilters ? angular.copy($scope._gridOptions.customFilters) : {};
$scope.urlSync = $scope._gridOptions.urlSync;

$scope.$watchCollection('_gridOptions.data', function (newValue) {
if (newValue && newValue.length > -1) {
$scope.sortCache = {};
$scope.filtered = $scope._gridOptions.data.slice();
$scope.filtered.resultSize = $scope._gridOptions.data.resultSize;
$scope.paginationOptions.totalItems = $scope.filtered.resultSize;
$scope.filters.forEach(function (filter) {
if (filter.filterType === 'select') {
$scope[filter.model + 'Options'] = generateOptions($scope.filtered, filter.filterBy);
Expand Down Expand Up @@ -270,7 +272,8 @@
}
$scope._time.sort = Date.now() - time3;
$scope._time.all = Date.now() - time;
$scope.paginationOptions.totalItems = $scope.filtered.length;

$scope.paginationOptions.totalItems = $scope.filtered.resultSize || $scope.filtered.length;
}

function applyCustomFilters() {
Expand Down Expand Up @@ -378,6 +381,9 @@
.factory('filtersFactory', function () {
function selectFilter(items, value, predicate) {
return items.filter(function (item) {
if(value == ("true" || "false")){
return value && item[predicate] ? item[predicate] === (value == 'true') : false;
}
return value && item[predicate] ? item[predicate] === value : true;
});
}
Expand All @@ -391,16 +397,36 @@
function dateToFilter(items, value, predicate) {
value = new Date(value).getTime();
return items.filter(function (item) {
if(item[predicate] instanceof Date == false){
var itemDate = new Date(item[predicate]);
return value && itemDate ? itemDate <= value + 86399999 : true;
}
return value && item[predicate] ? item[predicate] <= value + 86399999 : true;
});
}

function dateFromFilter(items, value, predicate) {
value = new Date(value).getTime();
return items.filter(function (item) {
if(item[predicate] instanceof Date == false){
var itemDate = new Date(item[predicate]);
return value && itemDate ? itemDate >= value : true;
}
return value && item[predicate] ? item[predicate] >= value : true;
});
}

function numberToFilter (items, value, predicate){
return items.filter(function (item) {
return isNaN(value) || isNaN(item[predicate]) || item[predicate] <= value;
});
}

function numberFromFilter(items, value, predicate){
return items.filter(function (item) {
return isNaN(value) || (!isNaN(item[predicate]) && item[predicate] >= value);
});
}

return {
getFilterByType: function (type) {
Expand All @@ -421,6 +447,12 @@
{
return dateFromFilter;
}
case 'numberTo': {
return numberToFilter;
}
case 'numberFrom' : {
return numberFromFilter;
}
default :
{
return null;
Expand All @@ -444,4 +476,4 @@
});
}
}
})();
})();