UNPKG

@progress/kendo-angular-grid

Version:

Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.

120 lines (119 loc) 4.95 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { Input, ContentChild, Directive } from "@angular/core"; import { ColumnComponent } from "../columns/column.component"; import { FilterInputDirective } from "./filter-input.directive"; import { isPresent, isNullOrEmptyString, isBlank, isChanged } from "../utils"; import { BaseFilterCellComponent } from "./base-filter-cell.component"; import { FilterService } from "./filter.service"; import * as i0 from "@angular/core"; import * as i1 from "./filter.service"; const EMPTY_VALUE_OPERATORS = new Set(['isnull', 'isnotnull', 'isempty', 'isnotempty']); const isEmptyValueOperator = (operator) => EMPTY_VALUE_OPERATORS.has(operator); /** * @hidden */ export class FilterInputWrapperComponent extends BaseFilterCellComponent { column; input; get currentFilter() { return this.filterByField(this.column.field); } get currentOperator() { const filter = this.currentFilter; if (!this._operator) { this._operator = filter ? filter.operator : this.defaultOperator; } return this._operator; } set currentOperator(value) { this._operator = value; const emptyValueOperator = isEmptyValueOperator(value); this.filterInputDisabled = emptyValueOperator; if (emptyValueOperator) { this.applyNoValueFilter(value); } else if (!isBlank(value) && isPresent(this.currentFilter)) { this.onChange(this.currentFilter.value); } } get defaultOperator() { if (!isNullOrEmptyString(this._defaultOperator)) { return this._defaultOperator; } else if (this.operators && this.operators.length) { return this.operators[0].value; } return "eq"; } set defaultOperator(value) { this._defaultOperator = value; } set filterInputDisabled(disabled) { if (!this.input) { return; } this.input.disabled = disabled; } _defaultOperator; _operator; changeSubscription; constructor(filterService) { super(filterService); } ngAfterContentInit() { if (isPresent(this.input)) { this.changeSubscription = this.input.change.subscribe(this.onChange.bind(this)); this.filterInputDisabled = isEmptyValueOperator(this.currentOperator); } } ngOnDestroy() { super.ngOnDestroy(); if (this.changeSubscription) { this.changeSubscription.unsubscribe(); } } onChange(value) { if (!isNullOrEmptyString(value) || this.filterByField(this.column.field)) { this.filterChange(isNullOrEmptyString(value) ? this.removeFilter(this.column.field) : this.updateFilter({ field: this.column.field, operator: this.currentOperator, value: value })); } } onClear() { this.onChange(null); this.filterInputDisabled = isEmptyValueOperator(this.defaultOperator); } applyNoValueFilter(operator) { this.filterChange(this.updateFilter({ field: this.column.field, operator: operator, value: null })); } ngOnChanges(changes) { if (isChanged("filter", changes, false)) { this._operator = null; this.filterInputDisabled = isEmptyValueOperator(this.currentOperator); } } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FilterInputWrapperComponent, deps: [{ token: i1.FilterService }], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: FilterInputWrapperComponent, inputs: { column: "column", defaultOperator: "defaultOperator" }, queries: [{ propertyName: "input", first: true, predicate: FilterInputDirective, descendants: true }], usesInheritance: true, usesOnChanges: true, ngImport: i0 }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: FilterInputWrapperComponent, decorators: [{ type: Directive, args: [{}] }], ctorParameters: function () { return [{ type: i1.FilterService }]; }, propDecorators: { column: [{ type: Input }], input: [{ type: ContentChild, args: [FilterInputDirective, { static: false }] }], defaultOperator: [{ type: Input }] } });