@@ -6,7 +6,7 @@ import { IFilteringExpressionsTree } from '../data-operations/filtering-expressi
6
6
import { Transaction , TransactionType , State } from '../services/transaction/transaction' ;
7
7
import { IgxCell , IgxGridCRUDService , IgxEditRow } from './common/crud.service' ;
8
8
import { CellType , ColumnType , GridServiceType , GridType , RowType } from './common/grid.interface' ;
9
- import { IGridEditEventArgs , IRowToggleEventArgs } from './common/events' ;
9
+ import { IGridEditEventArgs , IPinRowEventArgs , IRowToggleEventArgs } from './common/events' ;
10
10
import { IgxColumnMovingService } from './moving/moving.service' ;
11
11
import { IGroupingExpression } from '../data-operations/grouping-expression.interface' ;
12
12
import { ISortingExpression , SortingDirection } from '../data-operations/sorting-strategy' ;
@@ -151,6 +151,14 @@ export class GridBaseAPIService<T extends GridType> implements GridServiceType {
151
151
this . grid . validation . update ( cell . id . rowID , newRowData ) ;
152
152
}
153
153
if ( this . grid . primaryKey === cell . column . field ) {
154
+ if ( this . grid . pinnedRecords . length > 0 ) {
155
+ if ( this . grid . pinnedRecords . find ( r => r == cell . rowData ) ) {
156
+ const pinnedRowIndex = this . grid . pinnedRecords . indexOf ( cell . rowData ) ;
157
+ const previousRowId = cell . value ;
158
+ this . unpin_row ( previousRowId ) ;
159
+ this . pin_row ( args . newValue , pinnedRowIndex ) ;
160
+ }
161
+ }
154
162
if ( this . grid . selectionService . isRowSelected ( cell . id . rowID ) ) {
155
163
this . grid . selectionService . deselectRow ( cell . id . rowID ) ;
156
164
this . grid . selectionService . selectRowById ( args . newValue ) ;
@@ -543,6 +551,49 @@ export class GridBaseAPIService<T extends GridType> implements GridServiceType {
543
551
return DataUtil . sort ( cloneArray ( data ) , expressions , this . grid . sortStrategy , this . grid ) ;
544
552
}
545
553
554
+ public pin_row ( rowID : any , index ?: number , row ?: RowType ) : void {
555
+ const grid = ( this . grid as any ) ;
556
+ if ( grid . _pinnedRecordIDs . indexOf ( rowID ) !== - 1 ) {
557
+ return ;
558
+ }
559
+ const eventArgs = this . get_pin_row_event_args ( rowID , index , row , true ) ;
560
+ grid . rowPinning . emit ( eventArgs ) ;
561
+
562
+ if ( eventArgs . cancel ) {
563
+ return ;
564
+ }
565
+ const insertIndex = typeof eventArgs . insertAtIndex === 'number' ? eventArgs . insertAtIndex : grid . _pinnedRecordIDs . length ;
566
+ grid . _pinnedRecordIDs . splice ( insertIndex , 0 , rowID ) ;
567
+ }
568
+
569
+ public unpin_row ( rowID : any ) : void {
570
+ const grid = ( this . grid as any ) ;
571
+ const index = grid . _pinnedRecordIDs . indexOf ( rowID ) ;
572
+ if ( index === - 1 ) {
573
+ return ;
574
+ }
575
+ const eventArgs = this . get_pin_row_event_args ( rowID , null , null , false ) ;
576
+ grid . rowPinning . emit ( eventArgs ) ;
577
+
578
+ if ( eventArgs . cancel ) {
579
+ return ;
580
+ }
581
+ grid . _pinnedRecordIDs . splice ( index , 1 ) ;
582
+ }
583
+
584
+ public get_pin_row_event_args ( rowID : any , index ?: number , row ?: RowType , pinned ?: boolean ) {
585
+ const eventArgs : IPinRowEventArgs = {
586
+ isPinned : pinned ? true : false ,
587
+ rowID,
588
+ row,
589
+ cancel : false
590
+ }
591
+ if ( typeof index === 'number' ) {
592
+ eventArgs . insertAtIndex = index ;
593
+ }
594
+ return eventArgs ;
595
+ }
596
+
546
597
/**
547
598
* Updates related row of provided grid's data source with provided new row value
548
599
*
0 commit comments