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

Throw descriptive error when filtering without condition - 7.2.x #4899

Merged
merged 13 commits into from
Jun 10, 2019
Merged
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
All notable changes for each version of this project will be documented in this file.

## 7.2.12

- `IgxGrid`, `IgxTreeGrid`, `IgxHierarchicalGrid`
- **Breaking Change** The **condition** parameter of the `filterGlobal` method is no longer optional. When the filterGlobal method is called with an invalid condition, it will not clear the existing filters for all columns.

- `IgxGrid` - summaries
- `clearSummaryCache()` and `recalculateSummaries()` methods are now removed from the IgxGrid API, beacause they are no longer needed; summaries are updated when some change is perform and the summary cache is cleared automatically when needed;

### New feature
- **igxSlider** - exposing new `labels` property accepting a collection of literal values that become equally spread over the slider, by placing each element as a thumb label.
- **igxSlider** - deprecate **isContiunous** property.
Expand Down
12 changes: 7 additions & 5 deletions projects/igniteui-angular/src/lib/grids/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ export class GridBaseAPIService <T extends IgxGridBaseComponent & IGridDataBinda
}

public filter_global(term, condition, ignoreCase) {
if (!condition) {
return;
}

const grid = this.grid;
const filteringTree = grid.filteringExpressionsTree;
grid.endEdit(false);
Expand All @@ -318,11 +322,9 @@ export class GridBaseAPIService <T extends IgxGridBaseComponent & IGridDataBinda
}

filteringTree.filteringOperands = [];
if (condition) {
for (const column of grid.columns) {
this.prepare_filtering_expression(filteringTree, column.field, term,
condition, ignoreCase || column.filteringIgnoreCase);
}
for (const column of grid.columns) {
this.prepare_filtering_expression(filteringTree, column.field, term,
condition, ignoreCase || column.filteringIgnoreCase);
}

grid.filteringExpressionsTree = filteringTree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export class IgxFilteringService implements OnDestroy {
this.gridAPI.filter(field, value, conditionOrExpressionTree, filteringIgnoreCase);
} else {
const expressionsTreeForColumn = this.grid.filteringExpressionsTree.find(field);
if (expressionsTreeForColumn instanceof FilteringExpressionsTree) {
if (!expressionsTreeForColumn) {
throw new Error('Invalid condition or Expression Tree!');
} else if (expressionsTreeForColumn instanceof FilteringExpressionsTree) {
this.gridAPI.filter(field, value, expressionsTreeForColumn, filteringIgnoreCase);
} else {
const expressionForColumn = expressionsTreeForColumn as IFilteringExpression;
Expand Down Expand Up @@ -191,7 +193,7 @@ export class IgxFilteringService implements OnDestroy {
/**
* Filters all the `IgxColumnComponent` in the `IgxGridComponent` with the same condition.
*/
public filterGlobal(value: any, condition?, ignoreCase?) {
public filterGlobal(value: any, condition, ignoreCase?) {
this.gridAPI.filter_global(value, condition, ignoreCase);

// Wait for the change detection to update filtered data through the pipes and then emit the event.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3546,7 +3546,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
* @param ignoreCase
* @memberof IgxGridBaseComponent
*/
public filterGlobal(value: any, condition?, ignoreCase?) {
public filterGlobal(value: any, condition, ignoreCase?) {
this.filteringService.filterGlobal(value, condition, ignoreCase);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,27 @@ describe('IgxGrid - Filtering actions', () => {
verifyExpressionUI(expressionUIs[3], expression21, FilteringLogic.And, FilteringLogic.Or);
verifyExpressionUI(expressionUIs[4], expression22, null, FilteringLogic.And);
}));

it('Should throw descriptive error when filter() is called without condition', fakeAsync(() => {
expect(() => {
grid.filter('Downloads', 100);
fix.detectChanges();
}).toThrowError('Invalid condition or Expression Tree!');
}));

it('Should not clear previous filtering when filterGlobal() is called with invalid condition', fakeAsync(() => {
grid.filter('Downloads', 100, IgxNumberFilteringOperand.instance().condition('greaterThan'), true);
fix.detectChanges();
expect(grid.rowList.length).toEqual(4);
expect(grid.getCellByColumn(0, 'Downloads').value).toEqual(254);

// Execute global filtering with invalid condition.
grid.filterGlobal(1000, null);
fix.detectChanges();

expect(grid.rowList.length).toEqual(4);
expect(grid.getCellByColumn(0, 'Downloads').value).toEqual(254);
}));
});

const expectedResults = [];
Expand Down