Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow negative values in filter input - 18.0.x #14480

Open
wants to merge 2 commits into
base: 18.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
}

public set value(val) {
if (!val && val !== 0 && this.expression.searchVal) {
if (!val && val !== 0 && (this.expression.searchVal || this.expression.searchVal === 0)) {
this.expression.searchVal = null;
const index = this.expressionsList.findIndex(item => item.expression === this.expression);
if (index === 0 && this.expressionsList.length === 1) {
Expand All @@ -97,6 +97,9 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
return;
}
} else {
if (val === '') {
return;
}
const oldValue = this.expression.searchVal;
if (isEqual(oldValue, val)) {
return;
Expand Down Expand Up @@ -342,6 +345,9 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
// The 'iskeyPressed' flag is needed for a case in IE, because the input event is fired on focus and for some reason,
// when you have a japanese character as a placeholder, on init the value here is empty string .
const target = eventArgs.target;
if ((eventArgs.data === '-' || eventArgs.data === '+') && this.column.dataType === GridColumnDataType.Number) {
return;
}
if (this.column.dataType === GridColumnDataType.DateTime) {
this.value = eventArgs;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {
IgxGridExternalESFComponent,
IgxGridExternalESFTemplateComponent,
IgxGridDatesFilteringComponent,
LoadOnDemandFilterStrategy
LoadOnDemandFilterStrategy,
IgxGridFilteringNumericComponent
} from '../../test-utils/grid-samples.spec';
import { GridSelectionMode, FilterMode, Size } from '../common/enums';
import { ControlsFunction } from '../../test-utils/controls-functions.spec';
Expand Down Expand Up @@ -71,7 +72,8 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
IgxGridFilteringScrollComponent,
IgxGridFilteringMCHComponent,
IgxGridFilteringTemplateComponent,
IgxGridDatesFilteringComponent
IgxGridDatesFilteringComponent,
IgxGridFilteringNumericComponent
]
});
}));
Expand Down Expand Up @@ -904,6 +906,33 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
expect(input.properties.readOnly).toBeTruthy();
}));

it('should correctly filter negative values', fakeAsync(() => {
fix = TestBed.createComponent(IgxGridFilteringNumericComponent);
fix.detectChanges();
grid = fix.componentInstance.grid;

GridFunctions.clickFilterCellChip(fix, 'Number');

const filteringRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
const input = filteringRow.query(By.directive(IgxInputDirective));

// Set input and confirm
GridFunctions.typeValueInFilterRowInput('-1', fix);

expect(input.componentInstance.value).toEqual(-1);
expect(grid.rowList.length).toEqual(1);

GridFunctions.typeValueInFilterRowInput('0', fix);

expect(input.componentInstance.value).toEqual(0);
expect(grid.rowList.length).toEqual(0);

GridFunctions.typeValueInFilterRowInput('', fix);

expect(input.componentInstance.value).toEqual(null);
expect(grid.rowList.length).toEqual(3);
}));

it('Should focus input .', fakeAsync(() => {
GridFunctions.clickFilterCellChip(fix, 'ProductName');

Expand Down Expand Up @@ -2014,7 +2043,7 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {

// Select the first day
const firstDayItem: HTMLElement = calendar.querySelector('.igx-days-view__date:not(.igx-days-view__date--inactive)');

firstDayItem.firstChild.dispatchEvent(new Event('mousedown'));
grid.filteringRow.onInputGroupFocusout();
tick(200);
Expand Down
11 changes: 11 additions & 0 deletions projects/igniteui-angular/src/lib/test-utils/grid-samples.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,17 @@ export class IgxGridFilteringComponent extends BasicGridComponent {
}
}

@Component({
template: `<igx-grid [data]="data" height="500px" [allowFiltering]="true">
<igx-column width="100px" [field]="'Number'" [header]="'Number'" [filterable]="true" dataType="number"></igx-column>
</igx-grid>`,
standalone: true,
imports: [IgxGridComponent, IgxColumnComponent]
})
export class IgxGridFilteringNumericComponent extends BasicGridComponent {
public override data = SampleTestData.numericData();
}

@Component({
template: `<igx-grid [data]="data" height="500px" [allowFiltering]="true">
<igx-column width="100px" [field]="'ID'" [header]="'ID'" [hasSummary]="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export class SampleTestData {
{ Number: 3, String: '3', Boolean: true, Date: new Date(2018, 9, 22) }
]);

/* Fields: Number: number; 3 items. */
public static numericData = () => ([
{ Number: -1 },
{ Number: 2.5 },
{ Number: 35 }
]);

/* Fields: Name: string, Avatar: string; 3 items. */
public static personAvatarData = () => ([
{
Expand Down
Loading