@@ -7,7 +7,10 @@ import {
77 Optional ,
88 ViewChild ,
99 Inject ,
10- TemplateRef
10+ TemplateRef ,
11+ NgModuleRef ,
12+ OnInit ,
13+ OnDestroy
1114} from '@angular/core' ;
1215
1316import { IDisplayDensityOptions , DisplayDensityToken , DisplayDensityBase } from '../core/displayDensity' ;
@@ -18,15 +21,22 @@ import {
1821 IgxCsvExporterService ,
1922 IgxExcelExporterOptions ,
2023 IgxExcelExporterService ,
21- AbsoluteScrollStrategy
24+ AbsoluteScrollStrategy ,
25+ IgxOverlayService
2226} from '../services/index' ;
2327import { GridBaseAPIService } from './api.service' ;
2428import { IgxGridBaseComponent , IGridDataBindable } from './grid-base.component' ;
2529import { IgxDropDownComponent } from '../drop-down/drop-down.component' ;
2630import { IgxColumnHidingComponent } from './column-hiding.component' ;
2731import { IgxColumnPinningComponent } from './column-pinning.component' ;
2832import { OverlaySettings , PositionSettings , HorizontalAlignment , VerticalAlignment } from '../services/overlay/utilities' ;
29- import { ConnectedPositioningStrategy } from '../services/overlay/position' ;
33+ import { ConnectedPositioningStrategy , AutoPositionStrategy , GlobalPositionStrategy } from '../services/overlay/position' ;
34+ import { IgxAdvancedFilteringDialogComponent } from './filtering/advanced-filtering/advanced-filtering-dialog.component' ;
35+ import { IgxFilteringService } from './filtering/grid-filtering.service' ;
36+ import { filter , takeUntil } from 'rxjs/operators' ;
37+ import { Subject } from 'rxjs' ;
38+ import { useAnimation } from '@angular/animations' ;
39+ import { fadeIn , fadeOut } from '../animations/main' ;
3040
3141/**
3242 * This class encapsulates the Toolbar's logic and is internally used by
@@ -36,7 +46,8 @@ import { ConnectedPositioningStrategy } from '../services/overlay/position';
3646 selector : 'igx-grid-toolbar' ,
3747 templateUrl : './grid-toolbar.component.html'
3848} )
39- export class IgxGridToolbarComponent extends DisplayDensityBase {
49+ export class IgxGridToolbarComponent extends DisplayDensityBase implements OnInit , OnDestroy {
50+ private _componentOverlayId : string ;
4051
4152 /**
4253 * @hidden
@@ -218,10 +229,14 @@ export class IgxGridToolbarComponent extends DisplayDensityBase {
218229 public cdr : ChangeDetectorRef ,
219230 @Optional ( ) public excelExporter : IgxExcelExporterService ,
220231 @Optional ( ) public csvExporter : IgxCsvExporterService ,
221- @Optional ( ) @Inject ( DisplayDensityToken ) protected _displayDensityOptions : IDisplayDensityOptions ) {
232+ @Optional ( ) @Inject ( DisplayDensityToken ) protected _displayDensityOptions : IDisplayDensityOptions ,
233+ private _moduleRef : NgModuleRef < any > ,
234+ private _filteringService : IgxFilteringService ,
235+ @Inject ( IgxOverlayService ) private _overlayService : IgxOverlayService ) {
222236 super ( _displayDensityOptions ) ;
223237 }
224238
239+ private _destroy$ = new Subject < boolean > ( ) ;
225240 private _positionSettings : PositionSettings = {
226241 horizontalDirection : HorizontalAlignment . Left ,
227242 horizontalStartPoint : HorizontalAlignment . Right ,
@@ -237,6 +252,49 @@ export class IgxGridToolbarComponent extends DisplayDensityBase {
237252 excludePositionTarget : true
238253 } ;
239254
255+ // private _filterMenuPositionSettings = {
256+ // verticalStartPoint: VerticalAlignment.Bottom,
257+ // openAnimation: useAnimation(fadeIn, {
258+ // params: {
259+ // duration: '250ms'
260+ // }
261+ // }),
262+ // closeAnimation: useAnimation(fadeOut, {
263+ // params: {
264+ // duration: '200ms'
265+ // }
266+ // })
267+ // };
268+
269+ private _filterMenuOverlaySettings : OverlaySettings = {
270+ closeOnOutsideClick : false ,
271+ modal : true ,
272+ positionStrategy : new GlobalPositionStrategy ( ) , // new AutoPositionStrategy(this._filterMenuPositionSettings),
273+ scrollStrategy : new AbsoluteScrollStrategy ( )
274+ } ;
275+
276+ ngOnInit ( ) {
277+ this . _overlayService . onOpening . pipe (
278+ filter ( ( overlay ) => overlay . id === this . _componentOverlayId ) ,
279+ takeUntil ( this . _destroy$ ) ) . subscribe ( ( eventArgs ) => {
280+ this . onOverlayOpening ( eventArgs ) ;
281+ } ) ;
282+
283+ this . _overlayService . onClosed . pipe (
284+ filter ( overlay => overlay . id === this . _componentOverlayId ) ,
285+ takeUntil ( this . _destroy$ ) ) . subscribe ( ( ) => {
286+ this . onOverlayClosed ( ) ;
287+ } ) ;
288+ }
289+
290+ ngOnDestroy ( ) : void {
291+ this . _destroy$ . next ( true ) ;
292+ this . _destroy$ . complete ( ) ;
293+
294+ if ( this . _componentOverlayId ) {
295+ this . _overlayService . hide ( this . _componentOverlayId ) ;
296+ }
297+ }
240298
241299 /**
242300 * Returns the title of `IgxGridToolbarComponent`.
@@ -351,6 +409,29 @@ export class IgxGridToolbarComponent extends DisplayDensityBase {
351409 this . columnPinningDropdown . toggle ( this . _overlaySettings ) ;
352410 }
353411
412+ public showAdvancedFilteringUI ( ) {
413+ if ( ! this . _componentOverlayId ) {
414+ this . _filterMenuOverlaySettings . positionStrategy . settings . target =
415+ ( this . grid as any ) . rootGrid ? ( this . grid as any ) . rootGrid . nativeElement : this . grid . nativeElement ;
416+ this . _filterMenuOverlaySettings . outlet = this . grid . outletDirective ;
417+
418+ this . _componentOverlayId =
419+ this . _overlayService . attach ( IgxAdvancedFilteringDialogComponent , this . _filterMenuOverlaySettings , this . _moduleRef ) ;
420+ this . _overlayService . show ( this . _componentOverlayId , this . _filterMenuOverlaySettings ) ;
421+ }
422+ }
423+
424+ private onOverlayOpening ( eventArgs ) {
425+ const instance = eventArgs . componentRef . instance as IgxAdvancedFilteringDialogComponent ;
426+ if ( instance ) {
427+ instance . initialize ( this . _filteringService , this . _overlayService , eventArgs . id ) ;
428+ }
429+ }
430+
431+ private onOverlayClosed ( ) {
432+ this . _componentOverlayId = null ;
433+ }
434+
354435 /**
355436 * Returns the `context` object which represents the `template context` binding into the
356437 * `toolbar custom container` by providing references to the parent IgxGird and the toolbar itself.
0 commit comments