@@ -12,7 +12,10 @@ import {
1212 ChangeDetectionStrategy ,
1313 ViewRef ,
1414 HostListener ,
15- OnDestroy
15+ OnDestroy ,
16+ InjectionToken ,
17+ inject ,
18+ OnInit
1619} from '@angular/core' ;
1720import { GridColumnDataType , DataUtil } from '../../../data-operations/data-util' ;
1821import { IgxDropDownComponent } from '../../../drop-down/drop-down.component' ;
@@ -28,7 +31,7 @@ import { IgxDatePickerComponent } from '../../../date-picker/date-picker.compone
2831import { IgxTimePickerComponent } from '../../../time-picker/time-picker.component' ;
2932import { isEqual , PlatformUtil } from '../../../core/utils' ;
3033import { Subject } from 'rxjs' ;
31- import { takeUntil } from 'rxjs/operators' ;
34+ import { debounceTime , takeUntil } from 'rxjs/operators' ;
3235import { ExpressionUI } from '../excel-style/common' ;
3336import { ColumnType } from '../../common/grid.interface' ;
3437import { IgxRippleDirective } from '../../../directives/ripple/ripple.directive' ;
@@ -47,6 +50,14 @@ import { NgTemplateOutlet, NgClass } from '@angular/common';
4750import { IgxIconButtonDirective } from '../../../directives/button/icon-button.directive' ;
4851import { Size } from '../../common/enums' ;
4952
53+ /**
54+ * Injection token for setting the debounce time used in filtering row inputs.
55+ * @hidden
56+ */
57+ export const INPUT_DEBOUNCE_TIME = /*@__PURE__ */ new InjectionToken < number > ( 'INPUT_DEBOUNCE_TIME' , {
58+ factory : ( ) => 350
59+ } ) ;
60+
5061/**
5162 * @hidden
5263 */
@@ -56,7 +67,7 @@ import { Size } from '../../common/enums';
5667 templateUrl : './grid-filtering-row.component.html' ,
5768 imports : [ IgxDropDownComponent , IgxDropDownItemComponent , IgxChipsAreaComponent , IgxChipComponent , IgxIconComponent , IgxInputGroupComponent , IgxPrefixDirective , IgxDropDownItemNavigationDirective , IgxInputDirective , IgxSuffixDirective , IgxDatePickerComponent , IgxPickerToggleComponent , IgxPickerClearComponent , IgxTimePickerComponent , IgxDateTimeEditorDirective , NgTemplateOutlet , IgxButtonDirective , NgClass , IgxRippleDirective , IgxIconButtonDirective ]
5869} )
59- export class IgxGridFilteringRowComponent implements AfterViewInit , OnDestroy {
70+ export class IgxGridFilteringRowComponent implements OnInit , AfterViewInit , OnDestroy {
6071 @Input ( )
6172 public get column ( ) : ColumnType {
6273 return this . _column ;
@@ -196,7 +207,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
196207 /** switch to icon buttons when width is below 432px */
197208 private readonly NARROW_WIDTH_THRESHOLD = 432 ;
198209
210+ private inputSubject : Subject < KeyboardEvent > = new Subject < KeyboardEvent > ( ) ;
211+
199212 private $destroyer = new Subject < void > ( ) ;
213+ private readonly DEBOUNCE_TIME = inject ( INPUT_DEBOUNCE_TIME ) ;
200214
201215 constructor (
202216 public filteringService : IgxFilteringService ,
@@ -205,12 +219,22 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
205219 protected platform : PlatformUtil ,
206220 ) { }
207221
222+ public ngOnInit ( ) : void {
223+ this . inputSubject . pipe (
224+ debounceTime ( this . DEBOUNCE_TIME ) ,
225+ takeUntil ( this . $destroyer )
226+ ) . subscribe ( event => {
227+ this . handleInputChange ( event ) ;
228+ this . cdr . markForCheck ( ) ; // ChangeDetectionStrategy.OnPush is not picking the latest changes of the updated value because of the async pipe + debounce.
229+ } ) ;
230+ }
231+
208232 @HostListener ( 'keydown' , [ '$event' ] )
209233 public onKeydownHandler ( evt : KeyboardEvent ) {
210234 if ( this . platform . isFilteringKeyCombo ( evt ) ) {
211- evt . preventDefault ( ) ;
212- evt . stopPropagation ( ) ;
213- this . close ( ) ;
235+ evt . preventDefault ( ) ;
236+ evt . stopPropagation ( ) ;
237+ this . close ( ) ;
214238 }
215239 }
216240
@@ -225,10 +249,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
225249 }
226250
227251 this . filteringService . grid . localeChange
228- . pipe ( takeUntil ( this . $destroyer ) )
229- . subscribe ( ( ) => {
230- this . cdr . markForCheck ( ) ;
231- } ) ;
252+ . pipe ( takeUntil ( this . $destroyer ) )
253+ . subscribe ( ( ) => {
254+ this . cdr . markForCheck ( ) ;
255+ } ) ;
232256
233257 requestAnimationFrame ( ( ) => this . focusEditElement ( ) ) ;
234258 }
@@ -335,6 +359,10 @@ export class IgxGridFilteringRowComponent implements AfterViewInit, OnDestroy {
335359 * Event handler for input on the input.
336360 */
337361 public onInput ( eventArgs ) {
362+ this . inputSubject . next ( eventArgs ) ;
363+ }
364+
365+ private handleInputChange ( eventArgs ) {
338366 if ( ! eventArgs ) {
339367 return ;
340368 }
0 commit comments