Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
feat: Add option filterCaseSensitive
Browse files Browse the repository at this point in the history
You can use on specific control or directly on default settings
  • Loading branch information
TINANT Hervé committed Oct 30, 2017
1 parent 0a5ea4f commit 2edfe7d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ngx-tree-select/src/components/tree-select.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ export class TreeSelectComponent implements ControlValueAccessor {
return this.svc.Configuration.allowMultiple;
}

@Input()
public set filterCaseSensitive(value: boolean) {
this.svc.setConfiguration((opt) => opt.filterCaseSensitive = value, true);
}
public get filterCaseSensitive(): boolean {
return this.svc.Configuration.filterCaseSensitive;
}

@Input()
public set maxVisibleItemCount(value: number) {
this.svc.setConfiguration((opt) => opt.maxVisibleItemCount = value, true);
Expand Down Expand Up @@ -129,6 +137,11 @@ export class TreeSelectComponent implements ControlValueAccessor {
true :
defaultOpts.allowFilter
);
this.filterCaseSensitive = (
(defaultOpts.filterCaseSensitive === undefined || defaultOpts.filterCaseSensitive === null) ?
false :
defaultOpts.filterCaseSensitive
);
this.filterPlaceholder = (defaultOpts.filterPlaceholder || 'Type here for filtering items...');
this.idField = (defaultOpts.idField || 'id');
this.textField = (defaultOpts.textField || 'id');
Expand Down Expand Up @@ -235,7 +248,9 @@ export class TreeSelectComponent implements ControlValueAccessor {
result = this.ProcessMatchFilterTreeItem(child, filter) || result;
}
}
tree.matchFilter = (tree.id.indexOf(filter) > -1 || tree.text.indexOf(filter) > -1 || result);
tree.matchFilter = this.filterCaseSensitive ?
(tree.id.indexOf(filter) > -1 || tree.text.indexOf(filter) > -1 || result) :
(tree.id.toLowerCase().indexOf(filter.toLowerCase()) > -1 || tree.text.toLowerCase().indexOf(filter.toLowerCase()) > -1 || result);

return tree.matchFilter;
}
Expand Down
1 change: 1 addition & 0 deletions src/ngx-tree-select/src/models/select-option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class SelectOption {
public model: any[] | any;
public isOpen = false;
public filter = '';
public filterCaseSensitive = false;
public allowParentSelection = false;
public maxVisibleItemCount: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export class TreeSelectDefaultOptions {
public idField?: string;
public textField?: string;
public childrenField?: string;
public filterCaseSensitive?: boolean;
}

0 comments on commit 2edfe7d

Please sign in to comment.