Skip to content

Commit 973a750

Browse files
authored
Merge pull request #6337 from IgniteUI/dmdimitrov/issue6257-8.2.x
fix(adv-filtering): transforming search value based on column type #6257
2 parents 60ec1df + 383423c commit 973a750

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed

projects/igniteui-angular/src/lib/data-operations/data-util.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ export class DataUtil {
210210
return data;
211211
}
212212

213+
public static parseValue(dataType: DataType, value: any): any {
214+
if (dataType === DataType.Number) {
215+
value = parseFloat(value);
216+
}
217+
218+
return value;
219+
}
220+
213221
private static findParentFromPath(data: any[], primaryKey: any, childDataKey: any, path: any[]): any {
214222
let collection: any[] = data;
215223
let result: any;

projects/igniteui-angular/src/lib/grids/filtering/advanced-filtering/advanced-filtering-dialog.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { takeUntil, first } from 'rxjs/operators';
1818
import { Subject } from 'rxjs';
1919
import { KEYS } from '../../../core/utils';
2020
import { AbsoluteScrollStrategy, AutoPositionStrategy } from '../../../services/index';
21+
import { DataUtil } from './../../../data-operations/data-util';
2122

2223
/**
2324
*@hidden
@@ -301,7 +302,7 @@ export class IgxAdvancedFilteringDialogComponent implements AfterViewInit, OnDes
301302
if (this.editedExpression) {
302303
this.editedExpression.expression.fieldName = this.selectedColumn.field;
303304
this.editedExpression.expression.condition = this.selectedColumn.filters.condition(this.selectedCondition);
304-
this.editedExpression.expression.searchVal = this.searchValue;
305+
this.editedExpression.expression.searchVal = DataUtil.parseValue(this.selectedColumn.dataType, this.searchValue);
305306

306307
this.editedExpression.inEditMode = false;
307308
this.editedExpression = null;

projects/igniteui-angular/src/lib/grids/filtering/excel-style/excel-style-default-expression.component.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { ExpressionUI } from '../grid-filtering.service';
1313
import { IgxButtonGroupComponent } from '../../../buttonGroup/buttonGroup.component';
1414
import { IgxDropDownItemComponent, IgxDropDownComponent } from '../../../drop-down/index';
1515
import { IgxInputGroupComponent, IgxInputDirective } from '../../../input-group/index';
16-
import { DataType } from '../../../data-operations/data-util';
16+
import { DataType, DataUtil } from '../../../data-operations/data-util';
1717
import { IFilteringOperation } from '../../../data-operations/filtering-condition';
1818
import { OverlaySettings, ConnectedPositioningStrategy, CloseScrollStrategy } from '../../../services/index';
1919
import { KEYS, IBaseEventArgs } from '../../../core/utils';
@@ -167,7 +167,7 @@ export class IgxExcelStyleDefaultExpressionComponent implements AfterViewInit {
167167
}
168168

169169
public onValuesInput(eventArgs) {
170-
this.expressionUI.expression.searchVal = this.transformValue(eventArgs.target.value);
170+
this.expressionUI.expression.searchVal = DataUtil.parseValue(this.column.dataType, eventArgs.target.value);
171171
}
172172

173173
public onLogicOperatorButtonClicked(eventArgs, buttonIndex: number) {
@@ -207,14 +207,4 @@ export class IgxExcelStyleDefaultExpressionComponent implements AfterViewInit {
207207

208208
event.stopPropagation();
209209
}
210-
211-
private transformValue(value): any {
212-
if (this.column.dataType === DataType.Number) {
213-
value = parseFloat(value);
214-
} else if (this.column.dataType === DataType.Boolean) {
215-
value = Boolean(value);
216-
}
217-
218-
return value;
219-
}
220210
}

projects/igniteui-angular/src/lib/grids/filtering/grid-filtering-row.component.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
ChangeDetectionStrategy,
1414
ViewRef
1515
} from '@angular/core';
16-
import { DataType } from '../../data-operations/data-util';
16+
import { DataType, DataUtil } from '../../data-operations/data-util';
1717
import { IgxColumnComponent } from '../column.component';
1818
import { IgxDropDownComponent, ISelectionEventArgs } from '../../drop-down/index';
1919
import { IFilteringOperation } from '../../data-operations/filtering-condition';
@@ -100,7 +100,7 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
100100
this.expression.searchVal = null;
101101
this.showHideArrowButtons();
102102
} else {
103-
this.expression.searchVal = this.transformValue(val);
103+
this.expression.searchVal = DataUtil.parseValue(this.column.dataType, val);
104104
if (this.expressionsList.find(item => item.expression === this.expression) === undefined) {
105105
this.addExpression(true);
106106
}
@@ -659,16 +659,6 @@ export class IgxGridFilteringRowComponent implements AfterViewInit {
659659
});
660660
}
661661

662-
private transformValue(value): any {
663-
if (this.column.dataType === DataType.Number) {
664-
value = parseFloat(value);
665-
} else if (this.column.dataType === DataType.Boolean) {
666-
value = Boolean(value);
667-
}
668-
669-
return value;
670-
}
671-
672662
private addExpression(isSelected: boolean) {
673663
const exprUI = new ExpressionUI();
674664
exprUI.expression = this.expression;

projects/igniteui-angular/src/lib/grids/grid/grid-filtering-advanced.spec.ts

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ describe('IgxGrid - Advanced Filtering', () => {
419419
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('Ignite UI for Angular');
420420
}));
421421

422-
it('Should correctly filter by a \'number\' column through UI.', fakeAsync(() => {
422+
it('Should correctly filter by a \'Greater Than\' with \'number\' column through UI.', fakeAsync(() => {
423423
// Test prerequisites
424424
grid.height = '800px';
425425
fix.detectChanges();
@@ -461,6 +461,47 @@ describe('IgxGrid - Advanced Filtering', () => {
461461
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
462462
}));
463463

464+
it('Should correctly filter by a \'Equals\' with \'number\' column through UI.', fakeAsync(() => {
465+
// Test prerequisites
466+
grid.height = '800px';
467+
fix.detectChanges();
468+
tick(50);
469+
470+
// Verify no filters are present.
471+
expect(grid.filteredData).toBeNull();
472+
expect(grid.rowList.length).toBe(8);
473+
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('Ignite UI for JavaScript');
474+
expect(GridFunctions.getCurrentCellFromGrid(grid, 1, 1).value).toBe('NetAdvantage');
475+
476+
// Open Advanced Filtering dialog.
477+
GridFunctions.clickAdvancedFilteringButton(fix);
478+
fix.detectChanges();
479+
480+
// Click the initial 'Add And Group' button.
481+
const addAndGroupButton = GridFunctions.getAdvancedFilteringInitialAddGroupButtons(fix)[0];
482+
addAndGroupButton.click();
483+
tick(100);
484+
fix.detectChanges();
485+
486+
selectColumnInEditModeExpression(fix, 2); // Select 'Downloads' column.
487+
selectOperatorInEditModeExpression(fix, 0); // Select 'Equals' operator.
488+
const input = GridFunctions.getAdvancedFilteringValueInput(fix).querySelector('input');
489+
sendInputNativeElement(fix, input, '127'); // Type filter value.
490+
491+
// Commit the populated expression.
492+
GridFunctions.clickAdvancedFilteringExpressionCommitButton(fix);
493+
fix.detectChanges();
494+
495+
// Apply the filters.
496+
GridFunctions.clickAdvancedFilteringApplyButton(fix);
497+
fix.detectChanges();
498+
499+
// Verify the filter results.
500+
expect(grid.filteredData.length).toEqual(1);
501+
expect(grid.rowList.length).toBe(1);
502+
expect(GridFunctions.getCurrentCellFromGrid(grid, 0, 1).value).toBe('NetAdvantage');
503+
}));
504+
464505
it('Should correctly filter by a \'boolean\' column through UI.', fakeAsync(() => {
465506
// Test prerequisites
466507
grid.height = '800px';

0 commit comments

Comments
 (0)