Skip to content

Commit b3ed888

Browse files
committed
fix(adv-filtering): transforming search value based on column type #6257
1 parent 921a6df commit b3ed888

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

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

Lines changed: 12 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 { DataType } from 'igniteui-angular';
2122

2223
/**
2324
*@hidden
@@ -301,13 +302,23 @@ 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 = this.transformValue(this.searchValue);
305306

306307
this.editedExpression.inEditMode = false;
307308
this.editedExpression = null;
308309
}
309310
}
310311

312+
private transformValue(value): any {
313+
if (this.selectedColumn.dataType === DataType.Number) {
314+
value = parseFloat(value);
315+
} else if (this.selectedColumn.dataType === DataType.Boolean) {
316+
value = Boolean(value);
317+
}
318+
319+
return value;
320+
}
321+
311322
public cancelOperandAdd() {
312323
if (this.addModeExpression) {
313324
this.addModeExpression.inAddMode = false;

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)