Skip to content

Commit 1a5b043

Browse files
authored
Merge pull request #10344 from IgniteUI/hanastasov/date-column-master
Consider null values as filter value in date columns
2 parents b89e5a0 + 1675a01 commit 1a5b043

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

projects/igniteui-angular/src/lib/grids/state.directive.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ describe('IgxGridState - input properties #grid', () => {
178178
expect(gridState).toBe(filteringState);
179179
});
180180

181+
it('setState should correctly restore grid filtering state from with null date values', () => {
182+
const fix = TestBed.createComponent(IgxGridStateComponent);
183+
fix.detectChanges();
184+
const grid = fix.componentInstance.grid;
185+
grid.getCellByColumn(0, 'OrderDate').value = null;
186+
fix.detectChanges();
187+
const state = fix.componentInstance.state;
188+
189+
const filteringState = '{"filtering":{"filteringOperands":[{"filteringOperands":[{"condition":{"name":"empty","isUnary":true,"iconName":"is-empty"},"fieldName":"OrderDate","ignoreCase":true,"searchVal":null}],"operator":1,"fieldName":"OrderDate"}],"operator":0,"type":0}}';
190+
const initialState = '{"filtering":{"filteringOperands":[],"operator":0}}';
191+
192+
let gridState = state.getState(true, 'filtering');
193+
expect(gridState).toBe(initialState);
194+
195+
state.setState(filteringState);
196+
gridState = state.getState(false, 'filtering') as IGridState;
197+
HelperFunctions.verifyFilteringExpressions(grid.filteringExpressionsTree, gridState);
198+
gridState = state.getState(true, 'filtering');
199+
expect(gridState).toBe(filteringState);
200+
});
201+
181202
it('setState should correctly restore grid filtering state from object', () => {
182203
const fix = TestBed.createComponent(IgxGridStateComponent);
183204
fix.detectChanges();

projects/igniteui-angular/src/lib/grids/state.directive.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ export class IgxGridStateDirective {
549549
if (Array.isArray(expr.searchVal)) {
550550
expr.searchVal = new Set(expr.searchVal);
551551
} else {
552-
expr.searchVal = (dataType === 'date') ? new Date(Date.parse(expr.searchVal)) : expr.searchVal;
552+
expr.searchVal = expr.searchVal && (dataType === 'date') ? new Date(Date.parse(expr.searchVal)) : expr.searchVal;
553553
}
554554
expr.condition = this.generateFilteringCondition(dataType, expr.condition.name);
555555
expressionsTree.filteringOperands.push(expr);

0 commit comments

Comments
 (0)