@@ -23,7 +23,9 @@ import {
2323 ViewChildren ,
2424 ViewContainerRef ,
2525 InjectionToken ,
26- Optional
26+ Optional ,
27+ OnChanges ,
28+ SimpleChanges
2729} from '@angular/core' ;
2830import { Subject } from 'rxjs' ;
2931import { takeUntil , first , filter } from 'rxjs/operators' ;
@@ -233,8 +235,10 @@ export enum GridKeydownTargetType {
233235 hierarchicalRow = 'hierarchicalRow'
234236}
235237
236- export abstract class IgxGridBaseComponent extends DisplayDensityBase implements OnInit , OnDestroy , AfterContentInit , AfterViewInit {
238+ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
239+ OnInit , OnChanges , OnDestroy , AfterContentInit , AfterViewInit {
237240 private _scrollWidth : number ;
241+ protected _init = true ;
238242
239243 public get scrollWidth ( ) {
240244 return this . _scrollWidth ;
@@ -634,12 +638,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
634638 if ( this . _height !== value ) {
635639 this . _height = value ;
636640 this . _autoSize = false ;
637- requestAnimationFrame ( ( ) => {
638- if ( ! this . _destroyed ) {
639- this . reflow ( ) ;
640- this . cdr . markForCheck ( ) ;
641- }
642- } ) ;
641+ this . nativeElement . style . height = value ;
643642 }
644643 }
645644
@@ -653,28 +652,13 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
653652 @WatchChanges ( )
654653 @HostBinding ( 'style.width' )
655654 @Input ( )
656- public get width ( ) {
655+ get width ( ) {
657656 return this . _width ;
658657 }
659-
660- /**
661- * Sets the width of the `IgxGridComponent`.
662- * ```html
663- * <igx-grid #grid [data]="Data" [width]="'305px'" [autoGenerate]="true"></igx-grid>
664- * ```
665- * @memberof IgxGridBaseComponent
666- */
667- public set width ( value : string ) {
658+ set width ( value ) {
668659 if ( this . _width !== value ) {
669660 this . _width = value ;
670- requestAnimationFrame ( ( ) => {
671- // Calling reflow(), because the width calculation
672- // might make the horizontal scrollbar appear/disappear.
673- // This will change the height, which should be recalculated.
674- if ( ! this . _destroyed ) {
675- this . reflow ( ) ;
676- }
677- } ) ;
661+ this . nativeElement . style . width = value ;
678662 }
679663 }
680664
@@ -686,7 +670,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
686670 * @memberof IgxGridBaseComponent
687671 */
688672 get headerWidth ( ) {
689- return parseInt ( this . _width , 10 ) - 17 ;
673+ return parseInt ( this . width , 10 ) - 17 ;
690674 }
691675
692676 /**
@@ -1986,49 +1970,6 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
19861970 this . cdr . markForCheck ( ) ;
19871971 }
19881972
1989- /**
1990- * Returns the state of the grid virtualization, including the start index and how many records are rendered.
1991- * ```typescript
1992- * const gridVirtState = this.grid1.virtualizationState;
1993- * ```
1994- * @memberof IgxGridBaseComponent
1995- */
1996- get virtualizationState ( ) {
1997- return this . verticalScrollContainer . state ;
1998- }
1999-
2000- /**
2001- * @hidden
2002- */
2003- set virtualizationState ( state ) {
2004- this . verticalScrollContainer . state = state ;
2005- }
2006-
2007- /**
2008- * Returns the total number of records in the data source.
2009- * Works only with remote grid virtualization.
2010- * ```typescript
2011- * const itemCount = this.grid1.totalItemCount;
2012- * ```
2013- * @memberof IgxGridBaseComponent
2014- */
2015- get totalItemCount ( ) {
2016- return this . verticalScrollContainer . totalItemCount ;
2017- }
2018-
2019- /**
2020- * Sets the total number of records in the data source.
2021- * This property is required for virtualization to function when the grid is bound remotely.
2022- * ```typescript
2023- * this.grid1.totalItemCount = 55;
2024- * ```
2025- * @memberof IgxGridBaseComponent
2026- */
2027- set totalItemCount ( count ) {
2028- this . verticalScrollContainer . totalItemCount = count ;
2029- this . cdr . detectChanges ( ) ;
2030- }
2031-
20321973 /**
20331974 * @hidden
20341975 */
@@ -2651,6 +2592,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
26512592 public summaryService : IgxGridSummaryService ,
26522593 @Optional ( ) @Inject ( DisplayDensityToken ) protected _displayDensityOptions : IDisplayDensityOptions ) {
26532594 super ( _displayDensityOptions ) ;
2595+ this . cdr . detach ( ) ;
26542596 this . resizeHandler = ( ) => {
26552597 this . zone . run ( ( ) => this . calculateGridSizes ( ) ) ;
26562598 } ;
@@ -2664,6 +2606,14 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
26642606 this . summaryService . grid = this ;
26652607 }
26662608
2609+ ngOnChanges ( changes : SimpleChanges ) {
2610+ if ( this . _init ) { return ; }
2611+ const { height, width } = changes ;
2612+ if ( height || width ) {
2613+ this . calculateGridSizes ( ) ;
2614+ }
2615+ }
2616+
26672617 _setupListeners ( ) {
26682618 const destructor = takeUntil ( this . destroy$ ) ;
26692619
@@ -2715,7 +2665,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
27152665 this . _setupServices ( ) ;
27162666 this . _setupListeners ( ) ;
27172667 this . columnListDiffer = this . differs . find ( [ ] ) . create ( null ) ;
2718- this . calcWidth = this . _width && this . _width . indexOf ( '%' ) === - 1 ? parseInt ( this . _width , 10 ) : 0 ;
2668+ this . calcWidth = this . width && this . width . indexOf ( '%' ) === - 1 ? parseInt ( this . width , 10 ) : 0 ;
27192669 this . shouldGenerate = this . autoGenerate ;
27202670 this . _scrollWidth = this . getScrollWidth ( ) ;
27212671 }
@@ -2870,6 +2820,8 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
28702820 }
28712821 } ) ;
28722822 } ) ;
2823+ this . _init = false ;
2824+ this . cdr . reattach ( ) ;
28732825 }
28742826
28752827 private combineForOfCollections ( dataList , summaryList ) {
@@ -4008,7 +3960,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
40083960 * @hidden
40093961 */
40103962 protected get isPercentWidth ( ) {
4011- return this . _width && this . _width . indexOf ( '%' ) !== - 1 ;
3963+ return this . width && this . width . indexOf ( '%' ) !== - 1 ;
40123964 }
40133965
40143966 /**
@@ -4031,6 +3983,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
40313983 column . defaultWidth = columnWidthCombined + 'px' ;
40323984 } else {
40333985 column . defaultWidth = this . _columnWidth ;
3986+ column . resetCaches ( ) ;
40343987 }
40353988 } ) ;
40363989 this . resetCachedWidths ( ) ;
@@ -4041,7 +3994,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
40413994 * @hidden
40423995 */
40433996 protected get defaultTargetBodyHeight ( ) : number {
4044- const allItems = this . totalItemCount || this . dataLength ;
3997+ const allItems = this . dataLength ;
40453998 return this . renderedRowHeight * Math . min ( this . _defaultTargetRecordNumber ,
40463999 this . paging ? Math . min ( allItems , this . perPage ) : allItems ) ;
40474000 }
@@ -4232,7 +4185,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
42324185 width = computed . getPropertyValue ( 'width' ) . indexOf ( '%' ) === - 1 ?
42334186 parseInt ( computed . getPropertyValue ( 'width' ) , 10 ) : null ;
42344187 } else {
4235- width = parseInt ( this . _width , 10 ) ;
4188+ width = parseInt ( this . width , 10 ) ;
42364189 }
42374190
42384191 if ( ! width && el ) {
@@ -4391,7 +4344,7 @@ export abstract class IgxGridBaseComponent extends DisplayDensityBase implements
43914344 protected getUnpinnedWidth ( takeHidden = false ) {
43924345 let width = this . isPercentWidth ?
43934346 this . calcWidth :
4394- parseInt ( this . _width , 10 ) ;
4347+ parseInt ( this . width , 10 ) ;
43954348 if ( this . hasVerticalSroll ( ) && ! this . isPercentWidth ) {
43964349 width -= this . scrollWidth ;
43974350 }
0 commit comments