@@ -147,6 +147,7 @@ import { IgxColumnComponent } from './columns/column.component';
147
147
import { IgxColumnGroupComponent } from './columns/column-group.component' ;
148
148
import { IGridSortingStrategy } from '../data-operations/sorting-strategy' ;
149
149
import { IgxRowDragGhostDirective , IgxDragIndicatorIconDirective } from './row-drag.directive' ;
150
+ import { isNumber } from 'util' ;
150
151
151
152
const MINIMUM_COLUMN_WIDTH = 136 ;
152
153
const FILTER_ROW_HEIGHT = 50 ;
@@ -603,6 +604,13 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
603
604
this . notifyChanges ( ) ;
604
605
}
605
606
607
+ /**
608
+ * @hidden
609
+ * @internal
610
+ */
611
+ @Input ( )
612
+ public class = '' ;
613
+
606
614
/**
607
615
* Gets/Sets the height.
608
616
* @example
@@ -632,6 +640,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
632
640
get hostWidth ( ) {
633
641
return this . _width || this . _hostWidth ;
634
642
}
643
+
635
644
/**
636
645
* Gets/Sets the width of the grid.
637
646
* @example
@@ -1747,8 +1756,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
1747
1756
/**
1748
1757
* @hidden @internal
1749
1758
*/
1750
- @ViewChild ( 'pinContainer' , { static : false } )
1751
- public pinContainer : ElementRef ;
1759
+ @ViewChildren ( 'pinContainer' , { read : ElementRef } )
1760
+ public pinContainers : QueryList < ElementRef > ;
1752
1761
1753
1762
/**
1754
1763
* @hidden @internal
@@ -1939,7 +1948,10 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
1939
1948
*/
1940
1949
@HostBinding ( 'attr.class' )
1941
1950
get hostClass ( ) : string {
1942
- return this . getComponentDensityClass ( 'igx-grid' ) ;
1951
+ const classes = [ this . getComponentDensityClass ( 'igx-grid' ) ] ;
1952
+ // The custom classes should be at the end.
1953
+ classes . push ( this . class ) ;
1954
+ return classes . join ( ' ' ) ;
1943
1955
}
1944
1956
1945
1957
get bannerClass ( ) : string {
@@ -2410,6 +2422,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2410
2422
*/
2411
2423
protected destroy$ = new Subject < any > ( ) ;
2412
2424
2425
+ protected _filteredSortedPinnedData ;
2426
+ protected _filteredSortedUnpinnedData ;
2427
+ protected _filteredPinnedData ;
2428
+ protected _filteredUnpinnedData ;
2429
+
2413
2430
/**
2414
2431
* @hidden
2415
2432
*/
@@ -2479,15 +2496,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2479
2496
*/
2480
2497
protected _columnPinning = false ;
2481
2498
2482
-
2483
- /**
2484
- * @hidden
2485
- */
2486
- public get pinnedRecords ( ) {
2487
- return this . _pinnedRecords ;
2488
- }
2489
-
2490
- protected _pinnedRecords = [ ] ;
2499
+ protected _pinnedRecordIDs = [ ] ;
2491
2500
2492
2501
/**
2493
2502
* @hidden
@@ -2652,6 +2661,40 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2652
2661
} ) ;
2653
2662
}
2654
2663
2664
+ /**
2665
+ * @hidden
2666
+ * @internal
2667
+ */
2668
+ public isRecordPinned ( rec ) {
2669
+ const id = this . primaryKey ? rec [ this . primaryKey ] : rec ;
2670
+ return this . _pinnedRecordIDs . indexOf ( id ) !== - 1 ;
2671
+ }
2672
+
2673
+ /**
2674
+ * @hidden
2675
+ * @internal
2676
+ */
2677
+ public pinRecordIndex ( rec ) {
2678
+ const id = this . primaryKey ? rec [ this . primaryKey ] : rec ;
2679
+ return this . _pinnedRecordIDs . indexOf ( id ) ;
2680
+ }
2681
+
2682
+ /**
2683
+ * @hidden
2684
+ * @internal
2685
+ */
2686
+ public get hasPinnedRecords ( ) {
2687
+ return this . _pinnedRecordIDs . length > 0 ;
2688
+ }
2689
+
2690
+ /**
2691
+ * @hidden
2692
+ * @internal
2693
+ */
2694
+ public get pinnedRecordsCount ( ) {
2695
+ return this . _pinnedRecordIDs . length ;
2696
+ }
2697
+
2655
2698
private keydownHandler = ( event ) => {
2656
2699
const key = event . key . toLowerCase ( ) ;
2657
2700
if ( ( isNavigationKey ( key ) && event . keyCode !== 32 ) || key === 'tab' || key === 'pagedown' || key === 'pageup' ) {
@@ -2798,6 +2841,10 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2798
2841
this . endEdit ( true ) ;
2799
2842
this . cdr . markForCheck ( ) ;
2800
2843
} ) ;
2844
+
2845
+ this . onRowPinning . subscribe ( ( ) => {
2846
+ this . summaryService . clearSummaryCache ( ) ;
2847
+ } ) ;
2801
2848
}
2802
2849
2803
2850
/**
@@ -2847,6 +2894,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2847
2894
}
2848
2895
}
2849
2896
2897
+ public setFilterData ( data , pinned : boolean ) {
2898
+ if ( this . hasPinnedRecords && pinned ) {
2899
+ this . _filteredPinnedData = data ;
2900
+ this . filteredData = [ ... this . _filteredPinnedData , ... this . _filteredUnpinnedData ] ;
2901
+ } else if ( this . hasPinnedRecords && ! pinned ) {
2902
+ this . _filteredUnpinnedData = data ;
2903
+ } else {
2904
+ this . filteredData = data ;
2905
+ }
2906
+ }
2907
+
2850
2908
/**
2851
2909
* @hidden
2852
2910
* @internal
@@ -2890,6 +2948,22 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2890
2948
this . setupColumns ( ) ;
2891
2949
}
2892
2950
2951
+ /**
2952
+ * @hidden
2953
+ * @internal
2954
+ */
2955
+ public setFilteredSortedData ( data , pinned : boolean ) {
2956
+ if ( this . _pinnedRecordIDs . length > 0 && pinned ) {
2957
+ this . _filteredSortedPinnedData = data ;
2958
+ this . filteredSortedData = this . isRowPinningToTop ? [ ... this . _filteredSortedPinnedData , ... this . _filteredSortedUnpinnedData ] :
2959
+ [ ... this . _filteredSortedUnpinnedData , ... this . _filteredSortedPinnedData ] ;
2960
+ } else if ( this . _pinnedRecordIDs . length > 0 && ! pinned ) {
2961
+ this . _filteredSortedUnpinnedData = data ;
2962
+ } else {
2963
+ this . filteredSortedData = data ;
2964
+ }
2965
+ }
2966
+
2893
2967
/**
2894
2968
* @hidden @internal
2895
2969
*/
@@ -2938,6 +3012,12 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2938
3012
vertScrDC . addEventListener ( 'scroll' , this . scrollHandler ) ;
2939
3013
vertScrDC . addEventListener ( 'wheel' , ( ) => this . wheelHandler ( ) ) ;
2940
3014
3015
+ this . pinContainers . changes . subscribe ( ( c ) => {
3016
+ if ( this . hasPinnedRecords ) {
3017
+ // on row pin containers change grid sizes should be recalculated.
3018
+ this . calculateGridSizes ( ) ;
3019
+ }
3020
+ } ) ;
2941
3021
}
2942
3022
2943
3023
/**
@@ -3062,6 +3142,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
3062
3142
public set expansionStates ( value ) {
3063
3143
this . _expansionStates = new Map < any , boolean > ( value ) ;
3064
3144
this . expansionStatesChange . emit ( this . _expansionStates ) ;
3145
+ this . notifyChanges ( true ) ;
3065
3146
if ( this . gridAPI . grid ) {
3066
3147
this . cdr . detectChanges ( ) ;
3067
3148
}
@@ -4066,8 +4147,7 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4066
4147
* @param index The index at which to insert the row in the pinned collection.
4067
4148
*/
4068
4149
public pinRow ( rowID : any , index ?: number ) : boolean {
4069
- const rec = this . gridAPI . get_rec_by_id ( rowID ) ;
4070
- if ( ! rec || this . pinnedRecords . indexOf ( rec ) !== - 1 || this . data . indexOf ( rec ) === - 1 ) {
4150
+ if ( this . _pinnedRecordIDs . indexOf ( rowID ) !== - 1 ) {
4071
4151
return false ;
4072
4152
}
4073
4153
const row = this . gridAPI . get_row_by_key ( rowID ) ;
@@ -4080,7 +4160,10 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4080
4160
} ;
4081
4161
this . onRowPinning . emit ( eventArgs ) ;
4082
4162
4083
- this . pinnedRecords . splice ( eventArgs . insertAtIndex || this . pinnedRecords . length , 0 , rec ) ;
4163
+ this . endEdit ( true ) ;
4164
+
4165
+ const insertIndex = isNumber ( eventArgs . insertAtIndex ) ? eventArgs . insertAtIndex : this . _pinnedRecordIDs . length ;
4166
+ this . _pinnedRecordIDs . splice ( insertIndex , 0 , rowID ) ;
4084
4167
this . _pipeTrigger ++ ;
4085
4168
if ( this . gridAPI . grid ) {
4086
4169
this . notifyChanges ( true ) ;
@@ -4098,9 +4181,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4098
4181
* @param rowID The row id - primaryKey value or the data record instance.
4099
4182
*/
4100
4183
public unpinRow ( rowID : any ) {
4101
- const rec = this . gridAPI . get_rec_by_id ( rowID ) ;
4102
- const index = this . pinnedRecords . indexOf ( rec ) ;
4103
- if ( index === - 1 || ! rec ) {
4184
+ const index = this . _pinnedRecordIDs . indexOf ( rowID ) ;
4185
+ if ( index === - 1 ) {
4104
4186
return false ;
4105
4187
}
4106
4188
const row = this . gridAPI . get_row_by_key ( rowID ) ;
@@ -4110,7 +4192,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4110
4192
row : row
4111
4193
} ;
4112
4194
this . onRowPinning . emit ( eventArgs ) ;
4113
- this . pinnedRecords . splice ( index , 1 ) ;
4195
+ this . endEdit ( true ) ;
4196
+ this . _pinnedRecordIDs . splice ( index , 1 ) ;
4114
4197
this . _pipeTrigger ++ ;
4115
4198
if ( this . gridAPI . grid ) {
4116
4199
this . cdr . detectChanges ( ) ;
@@ -4120,8 +4203,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4120
4203
}
4121
4204
4122
4205
get pinnedRowHeight ( ) {
4123
- const containerHeight = this . pinContainer ? this . pinContainer . nativeElement . offsetHeight : 0 ;
4124
- return this . pinnedRecords . length > 0 ? containerHeight : 0 ;
4206
+ const pinContainer = this . pinContainers && this . pinContainers . length > 0 ? this . pinContainers . first : null ;
4207
+ const containerHeight = pinContainer ? pinContainer . nativeElement . offsetHeight : 0 ;
4208
+ return this . hasPinnedRecords ? containerHeight : 0 ;
4125
4209
}
4126
4210
4127
4211
get totalHeight ( ) {
0 commit comments