diff --git a/libs/mat-table-filter/src/lib/mat-table-filter-button/mat-table-filter-button.component.ts b/libs/mat-table-filter/src/lib/mat-table-filter-button/mat-table-filter-button.component.ts index 6e4e4f4..89a3e38 100644 --- a/libs/mat-table-filter/src/lib/mat-table-filter-button/mat-table-filter-button.component.ts +++ b/libs/mat-table-filter/src/lib/mat-table-filter-button/mat-table-filter-button.component.ts @@ -29,6 +29,7 @@ export class MatTableFilterButtonComponent { public intlService = inject(MatTableFilterIntlService); private cd = inject(ChangeDetectorRef); + private isCaseSensitive = true; operators: MatTableFilterDefaultOperator[] = []; _filterFormGroup: FormGroup = new FormGroup({ operator: new FormControl('', [Validators.required]), @@ -48,6 +49,7 @@ export class MatTableFilterButtonComponent ngOnInit(): void { if (this.headerType === 'string') { this.operators = MAT_TABLE_FILTER_STRING_DEFAULT_OPERATORS; + this.isCaseSensitive = this.sensitivityType; } else if (this.headerType === 'number') { this.operators = MAT_TABLE_FILTER_NUMBER_DEFAULT_OPERATORS; } @@ -62,6 +64,7 @@ export class MatTableFilterButtonComponent key: this.columnKey, operator: this._filterFormGroup.get('operator')?.value, input: this._filterFormGroup.get('input')?.value, + isCaseSensitive: this.isCaseSensitive, }); this._isFilterApplied = true; this.menuTrigger.closeMenu(); diff --git a/libs/mat-table-filter/src/lib/mat-table-filter-header.ts b/libs/mat-table-filter/src/lib/mat-table-filter-header.ts index 73d16f2..fb2bcea 100644 --- a/libs/mat-table-filter/src/lib/mat-table-filter-header.ts +++ b/libs/mat-table-filter/src/lib/mat-table-filter-header.ts @@ -16,6 +16,7 @@ import { } from './mat-table-filter-triggerer'; import {MatTableDefaultFilterSelection} from './models'; import {MatTableHeaderType} from './models/header-type'; +import {CaseSensitivityType} from './models/case-sensivity'; @Component({ // eslint-disable-next-line @angular-eslint/component-selector @@ -27,6 +28,7 @@ import {MatTableHeaderType} from './models/header-type'; export class MatTableFilterHeader implements AfterViewInit { @Input({required: false}) matTableFilterHeaderType: MatTableHeaderType = 'string'; + @Input({required: false}) isHeaderCaseSensitive: CaseSensitivityType = true; private triggererComponentType = inject(MAT_TABLE_TRIGGERER_TYPE); private triggererInstance?: MatTableTriggerer; @@ -58,6 +60,7 @@ export class MatTableFilterHeader implements AfterViewInit { ); this.triggererInstance = this._triggererComponentRef.instance; this.triggererInstance.headerType = this.matTableFilterHeaderType; + this.triggererInstance.sensitivityType = this.isHeaderCaseSensitive; } get selectedFilter$(): Observable { diff --git a/libs/mat-table-filter/src/lib/mat-table-filter-triggerer.ts b/libs/mat-table-filter/src/lib/mat-table-filter-triggerer.ts index 87e5774..0022b76 100644 --- a/libs/mat-table-filter/src/lib/mat-table-filter-triggerer.ts +++ b/libs/mat-table-filter/src/lib/mat-table-filter-triggerer.ts @@ -4,12 +4,14 @@ import {Observable, Subject} from 'rxjs'; import {MatTableFilterButtonComponent} from './mat-table-filter-button/mat-table-filter-button.component'; import {MatTableDefaultFilterSelection} from './models'; import {MatTableHeaderType} from './models/header-type'; +import {CaseSensitivityType} from './models/case-sensivity'; export class MatTableTriggerer { protected matColumnDef = inject(MatColumnDef); protected selectedFilterSubject = new Subject(); public headerType!: MatTableHeaderType; + public sensitivityType!: CaseSensitivityType; public parentHovered!: boolean; public get columnKey() { diff --git a/libs/mat-table-filter/src/lib/models/case-sensivity.ts b/libs/mat-table-filter/src/lib/models/case-sensivity.ts new file mode 100644 index 0000000..af80c95 --- /dev/null +++ b/libs/mat-table-filter/src/lib/models/case-sensivity.ts @@ -0,0 +1 @@ +export type CaseSensitivityType = true | false; \ No newline at end of file diff --git a/libs/mat-table-filter/src/lib/models/filter-selection.ts b/libs/mat-table-filter/src/lib/models/filter-selection.ts index cbfa832..7d11ea3 100644 --- a/libs/mat-table-filter/src/lib/models/filter-selection.ts +++ b/libs/mat-table-filter/src/lib/models/filter-selection.ts @@ -4,6 +4,7 @@ export type MatTableDefaultFilterSelection = { key: string; operator: MatTableFilterDefaultOperator; input?: string | boolean | number; + isCaseSensitive?: boolean; }; const MAT_TABLE_FILTER_STRING_DEFAULT_OPERATORS_MAP = { diff --git a/libs/mat-table-filter/src/lib/services/mat-table-filter.service.ts b/libs/mat-table-filter/src/lib/services/mat-table-filter.service.ts index 855413e..b93ad7c 100644 --- a/libs/mat-table-filter/src/lib/services/mat-table-filter.service.ts +++ b/libs/mat-table-filter/src/lib/services/mat-table-filter.service.ts @@ -42,7 +42,14 @@ export class MatTableFilterService { const value = data[filter.key] as string | number | boolean; if (value !== undefined) { - return this.operators[filter.operator](value, filter.input); + if (filter.isCaseSensitive == false) { + return this.operators[filter.operator]( + value.toString().toLowerCase(), + filter.input?.toString().toLowerCase() + ); + } else { + return this.operators[filter.operator](value, filter.input); + } } return true; });