@@ -32,7 +32,6 @@ const MINIMUM_COLUMN_WIDTH = 136;
3232 */
3333@Injectable ( )
3434export class IGridAPIService < T extends IGridBaseComponent > {
35-
3635 public change : Subject < any > = new Subject < any > ( ) ;
3736 protected state : Map < string , T > = new Map < string , T > ( ) ;
3837 protected editCellState : Map < string , any > = new Map < string , any > ( ) ;
@@ -113,9 +112,12 @@ export class IGridAPIService <T extends IGridBaseComponent> {
113112
114113 public on_after_view_init ( id : string ) {
115114 const grid = this . get ( id ) ;
116- this . zone . runOutsideAngular ( ( ) => {
117- this . document . defaultView . addEventListener ( 'resize' , this . resizeHandler ) ;
118- } ) ;
115+ // Subscribe only if we haven't got any active subscribtions
116+ if ( this . state . size === 0 ) {
117+ this . zone . runOutsideAngular ( ( ) => {
118+ this . document . defaultView . addEventListener ( 'resize' , this . resizeHandler ) ;
119+ } ) ;
120+ }
119121 this . calculate_grid_width ( id ) ;
120122 this . init_pinning ( id ) ;
121123 grid . reflow ( ) ;
@@ -154,9 +156,11 @@ export class IGridAPIService <T extends IGridBaseComponent> {
154156 }
155157
156158 public on_destroy ( id : string ) {
157- this . zone . runOutsideAngular ( ( ) => {
158- this . document . defaultView . removeEventListener ( 'resize' , this . resizeHandler ) ;
159- } ) ;
159+ if ( this . state . size === 1 ) {
160+ this . zone . runOutsideAngular ( ( ) => {
161+ this . document . defaultView . removeEventListener ( 'resize' , this . resizeHandler ) ;
162+ } ) ;
163+ }
160164 this . get_destroy ( id ) . next ( true ) ;
161165 this . get_destroy ( id ) . complete ( ) ;
162166 this . unset ( id ) ;
@@ -380,7 +384,7 @@ export class IGridAPIService <T extends IGridBaseComponent> {
380384 }
381385 }
382386
383- public sort_implementation ( id : string , fieldName : string , dir : SortingDirection , ignoreCase : boolean ) : void {
387+ private sort_implementation ( id : string , fieldName : string , dir : SortingDirection , ignoreCase : boolean ) : void {
384388 if ( dir === SortingDirection . None ) {
385389 this . remove_grouping_expression ( id , fieldName ) ;
386390 }
@@ -390,7 +394,7 @@ export class IGridAPIService <T extends IGridBaseComponent> {
390394 this . get ( id ) . sortingExpressions = sortingState ;
391395 }
392396
393- public sort_multiple_implementation ( id : string , expressions : ISortingExpression [ ] ) : void {
397+ private sort_multiple_implementation ( id : string , expressions : ISortingExpression [ ] ) : void {
394398 const sortingState = cloneArray ( this . get ( id ) . sortingExpressions ) ;
395399
396400 for ( const each of expressions ) {
@@ -472,7 +476,7 @@ export class IGridAPIService <T extends IGridBaseComponent> {
472476 this . clear_filter_implementation ( id , fieldName ) ;
473477 }
474478
475- public clear_filter_implementation ( id : string , fieldName : string ) {
479+ private clear_filter_implementation ( id : string , fieldName : string ) {
476480 if ( fieldName ) {
477481 const column = this . get_column_by_name ( id , fieldName ) ;
478482 if ( ! column ) {
@@ -509,7 +513,7 @@ export class IGridAPIService <T extends IGridBaseComponent> {
509513 this . clear_sort_implementation ( id , fieldName ) ;
510514 }
511515
512- public clear_sort_implementation ( id , fieldName ) {
516+ private clear_sort_implementation ( id , fieldName ) {
513517 const sortingState = this . get ( id ) . sortingExpressions ;
514518 const index = sortingState . findIndex ( ( expr ) => expr . fieldName === fieldName ) ;
515519 if ( index > - 1 ) {
@@ -1125,7 +1129,7 @@ export class IGridAPIService <T extends IGridBaseComponent> {
11251129 }
11261130
11271131 private subscribe_next ( virtualContainer : any , callback : ( elem ?) => void ) {
1128- virtualContainer . onChunkLoad . pipe ( take ( 1 ) ) . subscribe ( {
1132+ const subscription = virtualContainer . onChunkLoad . pipe ( take ( 1 ) ) . subscribe ( {
11291133 next : ( e : any ) => {
11301134 callback ( e ) ;
11311135 }
0 commit comments