Skip to content
Merged
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 @@ -68,14 +68,14 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
}

public set value(val) {
if (!val && val !== 0) {
if (!val && val !== 0 && this.expression.searchVal) {
this.expression.searchVal = null;
const index = this.expressionsList.findIndex(item => item.expression === this.expression);
if (index === 0 && this.expressionsList.length === 1) {
this.filteringService.clearFilter(this.column.field);

if (this.expression.condition.isUnary) {
this.resetExpression();
this.resetExpression(this.expression.condition.name);
}

return;
Expand Down Expand Up @@ -767,7 +767,7 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
this.showHideArrowButtons();
}

private resetExpression() {
private resetExpression(condition?: string) {
this.expression = {
fieldName: this.column.field,
condition: null,
Expand All @@ -776,7 +776,7 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
};

if (this.column.dataType !== GridColumnDataType.Boolean) {
this.expression.condition = this.getCondition(this.conditions[0]);
this.expression.condition = this.getCondition(condition ?? this.conditions[0]);
}

if (this.column.dataType === GridColumnDataType.Date && this.input) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2084,14 +2084,50 @@ describe('IgxGrid - Filtering Row UI actions #grid', () => {
// iterate over unary conditions
// empty
GridFunctions.openFilterDDAndSelectCondition(fix, 6);
expect(grid.filteringRow.expression.condition.name).toEqual('empty');

grid.filteringRow.onClearClick();
const filterUIRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
const reset = filterUIRow.queryAll(By.css('button'))[0];

reset.triggerEventHandler('click', null);
tick(100);
fix.detectChanges();

expect(grid.filteringRow.expression.condition.name).toEqual('contains');
}));

it('should reset expression to selected unary condition', fakeAsync(() => {
GridFunctions.clickFilterCellChip(fix, 'ReleaseDate');

const filterUIRow = fix.debugElement.query(By.directive(IgxGridFilteringRowComponent));
const datePicker = filterUIRow.query(By.directive(IgxDatePickerComponent));

// Equals condition
datePicker.triggerEventHandler('click', null);
tick();
fix.detectChanges();

const currentDay = document.querySelector('.igx-calendar__date--current');

currentDay.dispatchEvent(new Event('click'));
tick();
fix.detectChanges();

expect(grid.filteringRow.expression.condition.name).toEqual('equals');
expect(grid.rowList.length).toEqual(1);

// This Month condition
GridFunctions.openFilterDDAndSelectCondition(fix, 6);
tick();
fix.detectChanges();

expect(grid.filteringRow.expression.condition.name).toEqual('thisMonth');
expect(grid.rowList.length).toEqual(3);

const conditionChips = filterUIRow.queryAll(By.directive(IgxChipComponent));
expect(conditionChips.length).toBe(1);
}));

it('Should filter by cells formatted data when using FormattedValuesFilteringStrategy', fakeAsync(() => {
const formattedStrategy = new FormattedValuesFilteringStrategy(['Downloads']);
grid.filterStrategy = formattedStrategy;
Expand Down