Skip to content

Commit 0259aab

Browse files
committed
Add date flag to filters to be allow columsn to be filtered by dates.
1 parent 98cb0f0 commit 0259aab

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/js/core/services/rowSearcher.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil
134134
newFilter.condition = rowSearcher.guessCondition(filter);
135135
}
136136

137-
newFilter.flags = angular.extend( { caseSensitive: false }, filter.flags );
137+
newFilter.flags = angular.extend( { caseSensitive: false, date: false }, filter.flags );
138138

139139
if (newFilter.condition === uiGridConstants.filter.STARTS_WITH) {
140140
newFilter.startswithRE = new RegExp('^' + newFilter.term, regexpFlags);
@@ -221,6 +221,12 @@ module.service('rowSearcher', ['gridUtil', 'uiGridConstants', function (gridUtil
221221
}
222222
}
223223

224+
if (filter.flags.date === true) {
225+
value = new Date(value);
226+
// If the term has a dash in it, it comes through as '\-' -- we need to take out the '\'.
227+
term = new Date(term.replace(/\\/g, ''));
228+
}
229+
224230
if (filter.condition === uiGridConstants.filter.GREATER_THAN) {
225231
return (value > term);
226232
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
describe('rowSearcher', function() {
2+
var rowSearcher,
3+
uiGridConstants;
4+
5+
beforeEach(module('ui.grid'));
6+
7+
beforeEach(inject(function(_rowSearcher_, _uiGridConstants_) {
8+
rowSearcher = _rowSearcher_;
9+
uiGridConstants = _uiGridConstants_;
10+
}));
11+
12+
describe('runColumnFilter', function() {
13+
it('should be able to compare dates', function() {
14+
var grid = {
15+
getCellValue: function() {
16+
return '2015-05-23';
17+
}
18+
};
19+
20+
var filter = {
21+
term: '2015-05-24',
22+
flags: { date: true },
23+
condition: uiGridConstants.filter.GREATER_THAN
24+
};
25+
expect(rowSearcher.runColumnFilter(grid, 1, 2, filter)).toBe(false);
26+
27+
filter.term = '2015-05-22';
28+
filter.condition = uiGridConstants.filter.GREATER_THAN;
29+
expect(rowSearcher.runColumnFilter(grid, 1, 2, filter)).toBe(true);
30+
31+
filter.term = '2015-05-24';
32+
filter.condition = uiGridConstants.filter.GREATER_THAN;
33+
expect(rowSearcher.runColumnFilter(grid, 1, 2, filter)).toBe(false);
34+
35+
filter.term = '2015-05-23';
36+
filter.condition = uiGridConstants.filter.GREATER_THAN_OR_EQUAL_TO;
37+
expect(rowSearcher.runColumnFilter(grid, 1, 2, filter)).toBe(true);
38+
});
39+
});
40+
});

0 commit comments

Comments
 (0)