Skip to content

Commit f50aa0d

Browse files
committed
chore(*): apply requested changes
1 parent 8f52eee commit f50aa0d

File tree

3 files changed

+27
-39
lines changed

3 files changed

+27
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
autocomplete="off"
2828
[value]="value"
2929
(input)="onInput($event)"
30-
type="text"
30+
[type]="type"
3131
[readonly]="isUnaryCondition"
3232
(click)="onInputClick()"
3333
(compositionstart)="onCompositionStart()"

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ import { IgxIconButtonDirective } from '../../../directives/button/icon-button.d
5858
imports: [NgFor, IgxDropDownComponent, IgxDropDownItemComponent, IgxChipsAreaComponent, IgxChipComponent, IgxIconComponent, IgxInputGroupComponent, IgxPrefixDirective, IgxDropDownItemNavigationDirective, IgxInputDirective, NgIf, IgxSuffixDirective, IgxDatePickerComponent, IgxPickerToggleComponent, IgxPickerClearComponent, IgxTimePickerComponent, IgxDateTimeEditorDirective, NgTemplateOutlet, IgxButtonDirective, NgClass, IgxRippleDirective, IgxIconButtonDirective]
5959
})
6060
export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
61-
public ALLOWED_NUMERIC_SYMBOLS = ['+', '-', ',', '.'];
62-
public ALLOWED_NAVIGATION_SYMBOLS = ['Backspace', 'Enter', 'ArrowRight', 'ArrowLeft', 'Tab'];
63-
6461
@Input()
6562
public get column(): ColumnType {
6663
return this._column;
@@ -81,16 +78,14 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
8178
}
8279
}
8380

84-
private _value;
8581
@Input()
8682
public get value(): any {
87-
return this._value;
83+
return this.expression ? this.expression.searchVal : null;
8884
}
8985

9086
public set value(val) {
9187
if (!val && val !== 0 && (this.expression.searchVal || this.expression.searchVal === 0)) {
9288
this.expression.searchVal = null;
93-
this._value = null;
9489
const index = this.expressionsList.findIndex(item => item.expression === this.expression);
9590
if (index === 0 && this.expressionsList.length === 1) {
9691
this.filteringService.clearFilter(this.column.field);
@@ -102,18 +97,15 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
10297
return;
10398
}
10499
} else {
100+
if (val === '') {
101+
return;
102+
}
105103
const oldValue = this.expression.searchVal;
106104
if (isEqual(oldValue, val)) {
107105
return;
108106
}
109107

110-
this._value = val;
111-
if ((this.column.dataType === GridColumnDataType.Number || this.column.dataType === GridColumnDataType.Currency)
112-
&& this.ALLOWED_NUMERIC_SYMBOLS.includes(val)) {
113-
this.expression.searchVal = val;
114-
} else {
115-
this.expression.searchVal = DataUtil.parseValue(this.column.dataType, val);
116-
}
108+
this.expression.searchVal = DataUtil.parseValue(this.column.dataType, val);
117109
if (this.expressionsList.find(item => item.expression === this.expression) === undefined) {
118110
this.addExpression(true);
119111
}
@@ -246,7 +238,6 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
246238
const selectedItem = this.expressionsList.find(expr => expr.isSelected === true);
247239
if (selectedItem) {
248240
this.expression = selectedItem.expression;
249-
this._value = this.expression.searchVal;
250241
}
251242

252243
this.filteringService.grid.localeChange
@@ -275,6 +266,17 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
275266
return this.defaultFilterUI;
276267
}
277268

269+
public get type() {
270+
switch (this.column.dataType) {
271+
case GridColumnDataType.String:
272+
case GridColumnDataType.Boolean:
273+
return 'text';
274+
case GridColumnDataType.Number:
275+
case GridColumnDataType.Currency:
276+
return 'number';
277+
}
278+
}
279+
278280
public get conditions(): any {
279281
return this.column.filters.conditionList();
280282
}
@@ -317,12 +319,6 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
317319
public onInputKeyDown(event: KeyboardEvent) {
318320
this.isKeyPressed = true;
319321
event.stopPropagation();
320-
if(this.column.dataType === GridColumnDataType.Number || this.column.dataType === GridColumnDataType.Currency) {
321-
const allowedSymbols = [...this.ALLOWED_NUMERIC_SYMBOLS, ...this.ALLOWED_NAVIGATION_SYMBOLS];
322-
if (isNaN(Number(event.key)) && !(allowedSymbols.includes(event.key))) {
323-
event.preventDefault();
324-
}
325-
}
326322
if (this.column.dataType === GridColumnDataType.Boolean) {
327323
if (this.platform.isActivationKey(event)) {
328324
this.inputGroupPrefix.nativeElement.focus();
@@ -362,6 +358,9 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
362358
// The 'iskeyPressed' flag is needed for a case in IE, because the input event is fired on focus and for some reason,
363359
// when you have a japanese character as a placeholder, on init the value here is empty string .
364360
const target = eventArgs.target;
361+
if ((eventArgs.data === '-' || eventArgs.data === '+') && this.column.dataType === GridColumnDataType.Number) {
362+
return;
363+
}
365364
if (this.column.dataType === GridColumnDataType.DateTime) {
366365
this.value = eventArgs;
367366
return;
@@ -465,7 +464,6 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
465464
this.removeExpression(indexToDeselect, this.expression);
466465
}
467466
this.resetExpression();
468-
this._value = this.expression.searchVal;
469467
this.scrollChipsWhenAddingExpression();
470468
}
471469

@@ -639,7 +637,7 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
639637
item.isSelected = !item.isSelected;
640638
if (item.isSelected) {
641639
this.expression = item.expression;
642-
this._value = this.expression.searchVal;
640+
643641
this.focusEditElement();
644642
}
645643
}

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

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
906906
expect(input.properties.readOnly).toBeTruthy();
907907
}));
908908

909-
it('should correctly filter and display in input numeric values', fakeAsync(() => {
909+
it('should correctly filter negative values', fakeAsync(() => {
910910
fix = TestBed.createComponent(IgxGridFilteringNumericComponent);
911911
fix.detectChanges();
912912
grid = fix.componentInstance.grid;
@@ -919,22 +919,12 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
919919
// Set input and confirm
920920
GridFunctions.typeValueInFilterRowInput('-1', fix);
921921

922-
expect(input.componentInstance.value).toEqual('-1');
922+
expect(input.componentInstance.value).toEqual(-1);
923923
expect(grid.rowList.length).toEqual(1);
924924

925-
GridFunctions.typeValueInFilterRowInput('2.5', fix);
926-
927-
expect(input.componentInstance.value).toEqual('2.5');
928-
expect(grid.rowList.length).toEqual(1);
929-
930-
GridFunctions.typeValueInFilterRowInput('2.', fix);
931-
932-
expect(input.componentInstance.value).toEqual('2.');
933-
expect(grid.rowList.length).toEqual(0);
934-
935925
GridFunctions.typeValueInFilterRowInput('0', fix);
936926

937-
expect(input.componentInstance.value).toEqual('0');
927+
expect(input.componentInstance.value).toEqual(0);
938928
expect(grid.rowList.length).toEqual(0);
939929

940930
GridFunctions.typeValueInFilterRowInput('', fix);
@@ -2790,12 +2780,12 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
27902780
it('Should not prevent mousedown event when target is within the filter cell template', fakeAsync(() => {
27912781
const filterCell = GridFunctions.getFilterCell(fix, 'ProductName');
27922782
const input = filterCell.query(By.css('input')).nativeElement;
2793-
2783+
27942784
const mousedownEvent = new MouseEvent('mousedown', { bubbles: true });
27952785
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
27962786
input.dispatchEvent(mousedownEvent, { bubbles: true });
27972787
fix.detectChanges();
2798-
2788+
27992789
expect(preventDefaultSpy).not.toHaveBeenCalled();
28002790
}));
28012791

@@ -2807,7 +2797,7 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
28072797
const preventDefaultSpy = spyOn(mousedownEvent, 'preventDefault');
28082798
firstCell.dispatchEvent(mousedownEvent);
28092799
fix.detectChanges();
2810-
2800+
28112801
expect(preventDefaultSpy).toHaveBeenCalled();
28122802
}));
28132803
});

0 commit comments

Comments
 (0)