@@ -112,7 +112,8 @@ import {
112
112
GridSummaryPosition ,
113
113
GridSummaryCalculationMode ,
114
114
FilterMode ,
115
- ColumnPinningPosition
115
+ ColumnPinningPosition ,
116
+ RowPinningPosition
116
117
} from './common/enums' ;
117
118
import {
118
119
IGridCellEventArgs ,
@@ -133,7 +134,8 @@ import {
133
134
ISearchInfo ,
134
135
ICellPosition ,
135
136
IRowToggleEventArgs ,
136
- IColumnSelectionEventArgs
137
+ IColumnSelectionEventArgs ,
138
+ IPinRowEventArgs
137
139
} from './common/events' ;
138
140
import { IgxAdvancedFilteringDialogComponent } from './filtering/advanced-filtering/advanced-filtering-dialog.component' ;
139
141
import { GridType , IPinningConfig } from './common/grid.interface' ;
@@ -1388,6 +1390,16 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
1388
1390
@Output ( )
1389
1391
public onRowToggle = new EventEmitter < IRowToggleEventArgs > ( ) ;
1390
1392
1393
+ /**
1394
+ * Emitted when the pinned state of a row is changed.
1395
+ * @example
1396
+ * ```html
1397
+ * <igx-grid [data]="employeeData" (onRowPinning)="rowPin($event)" [autoGenerate]="true"></igx-grid>
1398
+ * ```
1399
+ */
1400
+ @Output ( )
1401
+ public onRowPinning = new EventEmitter < IPinRowEventArgs > ( ) ;
1402
+
1391
1403
/**
1392
1404
* @hidden @internal
1393
1405
*/
@@ -1632,6 +1644,14 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
1632
1644
return this . pinning . columns !== ColumnPinningPosition . End ;
1633
1645
}
1634
1646
1647
+ /**
1648
+ * @hidden
1649
+ * @internal
1650
+ */
1651
+ get isRowPinningToTop ( ) {
1652
+ return this . pinning . rows !== RowPinningPosition . Bottom ;
1653
+ }
1654
+
1635
1655
/**
1636
1656
* @hidden
1637
1657
* @internal
@@ -1724,6 +1744,12 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
1724
1744
@ViewChild ( 'tbody' , { static : true } )
1725
1745
public tbody : ElementRef ;
1726
1746
1747
+ /**
1748
+ * @hidden @internal
1749
+ */
1750
+ @ViewChild ( 'pinContainer' , { static : false } )
1751
+ public pinContainer : ElementRef ;
1752
+
1727
1753
/**
1728
1754
* @hidden @internal
1729
1755
*/
@@ -2454,6 +2480,15 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
2454
2480
protected _columnPinning = false ;
2455
2481
2456
2482
2483
+ /**
2484
+ * @hidden
2485
+ */
2486
+ public get pinnedRecords ( ) {
2487
+ return this . _pinnedRecords ;
2488
+ }
2489
+
2490
+ protected _pinnedRecords = [ ] ;
2491
+
2457
2492
/**
2458
2493
* @hidden
2459
2494
*/
@@ -3275,6 +3310,17 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
3275
3310
return this . _pinnedVisible ;
3276
3311
}
3277
3312
3313
+ /**
3314
+ * Gets an array of the pinned `IgxRowComponent`s.
3315
+ * @example
3316
+ * ```typescript
3317
+ * const pinnedRow = this.grid.pinnedRows;
3318
+ * ```
3319
+ */
3320
+ get pinnedRows ( ) : IgxGridRowComponent [ ] {
3321
+ return this . rowList . filter ( x => x . pinned ) ;
3322
+ }
3323
+
3278
3324
/**
3279
3325
* Gets an array of unpinned `IgxColumnComponent`s.
3280
3326
* @example
@@ -4008,6 +4054,87 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4008
4054
return col . unpin ( index ) ;
4009
4055
}
4010
4056
4057
+ /**
4058
+ * Pin the row by its id.
4059
+ * @remarks
4060
+ * ID is either the primaryKey value or the data record instance.
4061
+ * @example
4062
+ * ```typescript
4063
+ * this.grid.pinRow(rowID);
4064
+ * ```
4065
+ * @param rowID The row id - primaryKey value or the data record instance.
4066
+ * @param index The index at which to insert the row in the pinned collection.
4067
+ */
4068
+ 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 ) {
4071
+ return false ;
4072
+ }
4073
+ const row = this . gridAPI . get_row_by_key ( rowID ) ;
4074
+
4075
+ const eventArgs : IPinRowEventArgs = {
4076
+ insertAtIndex : index ,
4077
+ isPinned : true ,
4078
+ rowID : rowID ,
4079
+ row : row
4080
+ } ;
4081
+ this . onRowPinning . emit ( eventArgs ) ;
4082
+
4083
+ this . pinnedRecords . splice ( eventArgs . insertAtIndex || this . pinnedRecords . length , 0 , rec ) ;
4084
+ this . _pipeTrigger ++ ;
4085
+ if ( this . gridAPI . grid ) {
4086
+ this . notifyChanges ( true ) ;
4087
+ }
4088
+ }
4089
+
4090
+ /**
4091
+ * Unpin the row by its id.
4092
+ * @remarks
4093
+ * ID is either the primaryKey value or the data record instance.
4094
+ * @example
4095
+ * ```typescript
4096
+ * this.grid.unpinRow(rowID);
4097
+ * ```
4098
+ * @param rowID The row id - primaryKey value or the data record instance.
4099
+ */
4100
+ 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 ) {
4104
+ return false ;
4105
+ }
4106
+ const row = this . gridAPI . get_row_by_key ( rowID ) ;
4107
+ const eventArgs : IPinRowEventArgs = {
4108
+ isPinned : false ,
4109
+ rowID : rowID ,
4110
+ row : row
4111
+ } ;
4112
+ this . onRowPinning . emit ( eventArgs ) ;
4113
+ this . pinnedRecords . splice ( index , 1 ) ;
4114
+ this . _pipeTrigger ++ ;
4115
+ if ( this . gridAPI . grid ) {
4116
+ this . cdr . detectChanges ( ) ;
4117
+ this . notifyChanges ( true ) ;
4118
+ }
4119
+ return true ;
4120
+ }
4121
+
4122
+ get pinnedRowHeight ( ) {
4123
+ const containerHeight = this . pinContainer ? this . pinContainer . nativeElement . offsetHeight : 0 ;
4124
+ return this . pinnedRecords . length > 0 ? containerHeight : 0 ;
4125
+ }
4126
+
4127
+ get totalHeight ( ) {
4128
+ return this . calcHeight ? this . calcHeight + this . pinnedRowHeight : this . calcHeight ;
4129
+ }
4130
+
4131
+ get pinnedBottom ( ) {
4132
+ const start = this . verticalScrollContainer . state . startIndex ;
4133
+ const end = this . verticalScrollContainer . state . startIndex + this . verticalScrollContainer . state . chunkSize - 1 ;
4134
+ const bottom = this . verticalScrollContainer . getScrollForIndex ( end , true ) - this . verticalScrollContainer . getScrollForIndex ( start ) ;
4135
+ return bottom ;
4136
+ }
4137
+
4011
4138
4012
4139
/**
4013
4140
* Recalculates grid width/height dimensions.
@@ -4313,6 +4440,9 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4313
4440
}
4314
4441
4315
4442
this . calcHeight = this . _calculateGridBodyHeight ( ) ;
4443
+ if ( this . pinnedRowHeight && this . calcHeight ) {
4444
+ this . calcHeight -= this . pinnedRowHeight ;
4445
+ }
4316
4446
}
4317
4447
4318
4448
/**
0 commit comments