File tree 2 files changed +28
-1
lines changed
projects/igniteui-angular/src/lib/grids
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';
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 ;
@@ -4124,7 +4125,8 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
4124
4125
4125
4126
this . endEdit ( true ) ;
4126
4127
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 ) ;
4128
4130
this . _pipeTrigger ++ ;
4129
4131
if ( this . gridAPI . grid ) {
4130
4132
this . notifyChanges ( true ) ;
Original file line number Diff line number Diff line change @@ -120,6 +120,31 @@ describe('Row Pinning #grid', () => {
120
120
expect ( grid . calcHeight - expectedHeight ) . toBeLessThanOrEqual ( 1 ) ;
121
121
} ) ;
122
122
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
+
123
148
it ( 'should emit onRowPinning on pin/unpin.' , ( ) => {
124
149
spyOn ( grid . onRowPinning , 'emit' ) . and . callThrough ( ) ;
125
150
You can’t perform that action at this time.
0 commit comments