Skip to content

Commit 8ac232a

Browse files
committed
refactor(combos): move default filter function to combo pipe
1 parent ea92bdb commit 8ac232a

File tree

4 files changed

+24
-19
lines changed

4 files changed

+24
-19
lines changed

projects/igniteui-angular/src/lib/combo/combo.common.ts

+1-16
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
394394
*/
395395
@Input()
396396
public get filterFunction(): (collection: any[], searchValue: any, caseSensitive: boolean) => any[] {
397-
return this._customFilterFunction || this._defaultFilterFunction;
397+
return this._customFilterFunction;
398398
}
399399

400400
public set filterFunction(value: (collection: any[], searchValue: any, caseSensitive: boolean) => any[]) {
@@ -894,21 +894,6 @@ export abstract class IgxComboBaseDirective extends DisplayDensityBase implement
894894
protected destroy$ = new Subject<any>();
895895
protected _onTouchedCallback: () => void = noop;
896896
protected _onChangeCallback: (_: any) => void = noop;
897-
protected _defaultFilterFunction = (collection: any[], searchValue: any, matchCase: boolean): any[] => {
898-
if (!searchValue) {
899-
return collection;
900-
}
901-
const searchTerm = matchCase ? searchValue.trim() : searchValue.toLowerCase().trim();
902-
if (this.displayKey != null) {
903-
return collection.filter(e => matchCase ?
904-
e[this.displayKey]?.includes(searchTerm) :
905-
e[this.displayKey]?.toString().toLowerCase().includes(searchTerm));
906-
} else {
907-
return collection.filter(e => matchCase ?
908-
e.includes(searchTerm) :
909-
e.toString().toLowerCase().includes(searchTerm));
910-
}
911-
}
912897

913898
private _type = null;
914899
private _dataType = '';

projects/igniteui-angular/src/lib/combo/combo.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
[tabindex]="dropdown.collapsed ? -1 : 0" [attr.id]="dropdown.id" aria-multiselectable="true"
5353
[attr.aria-activedescendant]="this.activeDescendant">
5454
<igx-combo-item [itemHeight]='itemHeight' *igxFor="let item of data
55-
| comboFiltering:filterFunction:filterValue:filteringOptions:filterable
55+
| comboFiltering:filterFunction:filterValue:filteringOptions:filterable:displayKey
5656
| comboGrouping:groupKey:valueKey:groupSortingDirection;
5757
index as rowIndex; containerSize: itemsMaxHeight; scrollOrientation: 'vertical'; itemSize: itemHeight"
5858
[value]="item" [isHeader]="item.isHeader" [index]="rowIndex">

projects/igniteui-angular/src/lib/combo/combo.pipes.ts

+21-1
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,38 @@ export class IgxComboCleanPipe implements PipeTransform {
2020
name: 'comboFiltering'
2121
})
2222
export class IgxComboFilteringPipe implements PipeTransform {
23+
private displayKey: any;
24+
private _defaultFilterFunction = (collection: any[], searchValue: any, matchCase: boolean): any[] => {
25+
if (!searchValue) {
26+
return collection;
27+
}
28+
const searchTerm = matchCase ? searchValue.trim() : searchValue.toLowerCase().trim();
29+
if (this.displayKey != null) {
30+
return collection.filter(e => matchCase ?
31+
e[this.displayKey]?.includes(searchTerm) :
32+
e[this.displayKey]?.toString().toLowerCase().includes(searchTerm));
33+
} else {
34+
return collection.filter(e => matchCase ?
35+
e.includes(searchTerm) :
36+
e.toString().toLowerCase().includes(searchTerm));
37+
}
38+
}
39+
2340
public transform(
2441
collection: any[],
2542
filterFunction: (collection: any[], searchValue: any, caseSensitive: boolean) => any[],
2643
searchValue: any,
2744
filteringOptions: IComboFilteringOptions,
28-
filterable: boolean = true) {
45+
filterable: boolean,
46+
displayKey: any) {
2947
if (!collection) {
3048
return [];
3149
}
3250
if (!filterable) {
3351
return collection;
3452
}
53+
this.displayKey = displayKey;
54+
filterFunction = filterFunction ?? this._defaultFilterFunction;
3555
return filterFunction(collection, searchValue, filteringOptions.caseSensitive);
3656
}
3757
}

projects/igniteui-angular/src/lib/simple-combo/simple-combo.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
(keydown)="handleItemKeyDown($event)">
5353
<igx-combo-item role="option" [singleMode]="true" [itemHeight]='itemHeight' (click)="handleItemClick()" *igxFor="let item of data
5454
| comboClean
55-
| comboFiltering:filterFunction:filterValue:filteringOptions
55+
| comboFiltering:filterFunction:filterValue:filteringOptions:true:displayKey
5656
| comboGrouping:groupKey:valueKey:groupSortingDirection;
5757
index as rowIndex; containerSize: itemsMaxHeight; scrollOrientation: 'vertical'; itemSize: itemHeight"
5858
[value]="item" [isHeader]="item.isHeader" [index]="rowIndex">

0 commit comments

Comments
 (0)