File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
projects/igniteui-angular/src/lib/grids Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,7 @@ import { IgxColumnComponent } from './columns/column.component';
147147import { IgxColumnGroupComponent } from './columns/column-group.component' ;
148148import { IGridSortingStrategy } from '../data-operations/sorting-strategy' ;
149149import { IgxRowDragGhostDirective , IgxDragIndicatorIconDirective } from './row-drag.directive' ;
150+ import { isNumber } from 'util' ;
150151
151152const MINIMUM_COLUMN_WIDTH = 136 ;
152153const FILTER_ROW_HEIGHT = 50 ;
@@ -4124,7 +4125,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
41244125
41254126 this . endEdit ( true ) ;
41264127
4127- this . _pinnedRecordIDs . splice ( eventArgs . insertAtIndex || this . _pinnedRecordIDs . length , 0 , rowID ) ;
4128+ const insertIndex = isNumber ( eventArgs . insertAtIndex ) ? eventArgs . insertAtIndex : this . _pinnedRecordIDs . length ;
4129+ this . _pinnedRecordIDs . splice ( insertIndex , 0 , rowID ) ;
41284130 this . _pipeTrigger ++ ;
41294131 if ( this . gridAPI . grid ) {
41304132 this . notifyChanges ( true ) ;
Original file line number Diff line number Diff line change @@ -120,6 +120,31 @@ describe('Row Pinning #grid', () => {
120120 expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
121121 } ) ;
122122
123+ it ( 'should allow pinning row at specified index via API.' , ( ) => {
124+ grid . pinRow ( fix . componentInstance . data [ 1 ] ) ;
125+ fix . detectChanges ( ) ;
126+
127+ expect ( grid . pinnedRows . length ) . toBe ( 1 ) ;
128+ expect ( grid . pinnedRows [ 0 ] . rowData ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
129+
130+ // pin at index 0
131+ grid . pinRow ( fix . componentInstance . data [ 2 ] , 0 ) ;
132+ fix . detectChanges ( ) ;
133+
134+ expect ( grid . pinnedRows . length ) . toBe ( 2 ) ;
135+ expect ( grid . pinnedRows [ 0 ] . rowData ) . toBe ( fix . componentInstance . data [ 2 ] ) ;
136+ expect ( grid . pinnedRows [ 1 ] . rowData ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
137+
138+ // pin at index 1
139+ grid . pinRow ( fix . componentInstance . data [ 3 ] , 1 ) ;
140+ fix . detectChanges ( ) ;
141+
142+ expect ( grid . pinnedRows . length ) . toBe ( 3 ) ;
143+ expect ( grid . pinnedRows [ 0 ] . rowData ) . toBe ( fix . componentInstance . data [ 2 ] ) ;
144+ expect ( grid . pinnedRows [ 1 ] . rowData ) . toBe ( fix . componentInstance . data [ 3 ] ) ;
145+ expect ( grid . pinnedRows [ 2 ] . rowData ) . toBe ( fix . componentInstance . data [ 1 ] ) ;
146+ } ) ;
147+
123148 it ( 'should emit onRowPinning on pin/unpin.' , ( ) => {
124149 spyOn ( grid . onRowPinning , 'emit' ) . and . callThrough ( ) ;
125150
You can’t perform that action at this time.
0 commit comments