@@ -7,7 +7,10 @@ import {
7
7
Optional ,
8
8
ViewChild ,
9
9
Inject ,
10
- TemplateRef
10
+ TemplateRef ,
11
+ NgModuleRef ,
12
+ OnInit ,
13
+ OnDestroy
11
14
} from '@angular/core' ;
12
15
13
16
import { IDisplayDensityOptions , DisplayDensityToken , DisplayDensityBase } from '../core/displayDensity' ;
@@ -18,15 +21,22 @@ import {
18
21
IgxCsvExporterService ,
19
22
IgxExcelExporterOptions ,
20
23
IgxExcelExporterService ,
21
- AbsoluteScrollStrategy
24
+ AbsoluteScrollStrategy ,
25
+ IgxOverlayService
22
26
} from '../services/index' ;
23
27
import { GridBaseAPIService } from './api.service' ;
24
28
import { IgxGridBaseComponent , IGridDataBindable } from './grid-base.component' ;
25
29
import { IgxDropDownComponent } from '../drop-down/drop-down.component' ;
26
30
import { IgxColumnHidingComponent } from './column-hiding.component' ;
27
31
import { IgxColumnPinningComponent } from './column-pinning.component' ;
28
32
import { 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' ;
30
40
31
41
/**
32
42
* This class encapsulates the Toolbar's logic and is internally used by
@@ -36,7 +46,8 @@ import { ConnectedPositioningStrategy } from '../services/overlay/position';
36
46
selector : 'igx-grid-toolbar' ,
37
47
templateUrl : './grid-toolbar.component.html'
38
48
} )
39
- export class IgxGridToolbarComponent extends DisplayDensityBase {
49
+ export class IgxGridToolbarComponent extends DisplayDensityBase implements OnInit , OnDestroy {
50
+ private _componentOverlayId : string ;
40
51
41
52
/**
42
53
* @hidden
@@ -218,10 +229,14 @@ export class IgxGridToolbarComponent extends DisplayDensityBase {
218
229
public cdr : ChangeDetectorRef ,
219
230
@Optional ( ) public excelExporter : IgxExcelExporterService ,
220
231
@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 ) {
222
236
super ( _displayDensityOptions ) ;
223
237
}
224
238
239
+ private _destroy$ = new Subject < boolean > ( ) ;
225
240
private _positionSettings : PositionSettings = {
226
241
horizontalDirection : HorizontalAlignment . Left ,
227
242
horizontalStartPoint : HorizontalAlignment . Right ,
@@ -237,6 +252,49 @@ export class IgxGridToolbarComponent extends DisplayDensityBase {
237
252
excludePositionTarget : true
238
253
} ;
239
254
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
+ }
240
298
241
299
/**
242
300
* Returns the title of `IgxGridToolbarComponent`.
@@ -351,6 +409,29 @@ export class IgxGridToolbarComponent extends DisplayDensityBase {
351
409
this . columnPinningDropdown . toggle ( this . _overlaySettings ) ;
352
410
}
353
411
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
+
354
435
/**
355
436
* Returns the `context` object which represents the `template context` binding into the
356
437
* `toolbar custom container` by providing references to the parent IgxGird and the toolbar itself.
0 commit comments