@@ -6,7 +6,7 @@ import { IFilteringExpressionsTree } from '../data-operations/filtering-expressi
66import { Transaction , TransactionType , State } from '../services/transaction/transaction' ;
77import { IgxCell , IgxGridCRUDService , IgxEditRow } from './common/crud.service' ;
88import { CellType , ColumnType , GridServiceType , GridType , RowType } from './common/grid.interface' ;
9- import { IGridEditEventArgs , IRowToggleEventArgs } from './common/events' ;
9+ import { IGridEditEventArgs , IPinRowEventArgs , IRowToggleEventArgs } from './common/events' ;
1010import { IgxColumnMovingService } from './moving/moving.service' ;
1111import { IGroupingExpression } from '../data-operations/grouping-expression.interface' ;
1212import { ISortingExpression , SortingDirection } from '../data-operations/sorting-strategy' ;
@@ -151,6 +151,14 @@ export class GridBaseAPIService<T extends GridType> implements GridServiceType {
151151 this . grid . validation . update ( cell . id . rowID , newRowData ) ;
152152 }
153153 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+ }
154162 if ( this . grid . selectionService . isRowSelected ( cell . id . rowID ) ) {
155163 this . grid . selectionService . deselectRow ( cell . id . rowID ) ;
156164 this . grid . selectionService . selectRowById ( args . newValue ) ;
@@ -543,6 +551,49 @@ export class GridBaseAPIService<T extends GridType> implements GridServiceType {
543551 return DataUtil . sort ( cloneArray ( data ) , expressions , this . grid . sortStrategy , this . grid ) ;
544552 }
545553
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+
546597 /**
547598 * Updates related row of provided grid's data source with provided new row value
548599 *
0 commit comments