@@ -4082,33 +4082,43 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
4082
4082
* @hidden @internal
4083
4083
*/
4084
4084
public beginAddRowByIndex ( rowID : any , index : number , asChild ?: boolean ) {
4085
+ if ( ! this . rowEditable ) {
4086
+ console . warn ( 'The grid must use row edit mode to perform row adding! Please set rowEditable to true.' ) ;
4087
+ return ;
4088
+ }
4085
4089
this . endEdit ( true ) ;
4086
4090
this . cancelAddMode = false ;
4091
+ const isInPinnedArea = this . isRecordPinnedByViewIndex ( index ) ;
4092
+ const pinIndex = this . pinnedRecords . findIndex ( x => x [ this . primaryKey ] === rowID ) ;
4093
+ const unpinIndex = this . getUnpinnedIndexById ( rowID ) ;
4087
4094
4088
4095
if ( this . expansionStates . get ( rowID ) ) {
4089
4096
this . collapseRow ( rowID ) ;
4090
4097
}
4091
4098
4092
4099
this . addRowParent = {
4093
4100
rowID : rowID ,
4094
- index : index ,
4095
- asChild : asChild
4101
+ index : isInPinnedArea ? pinIndex : unpinIndex ,
4102
+ asChild : asChild ,
4103
+ isPinned : isInPinnedArea
4096
4104
} ;
4097
- this . verticalScrollContainer . onDataChanged . pipe ( first ( ) ) . subscribe ( ( ) => {
4098
- this . cdr . detectChanges ( ) ;
4099
- const newRowIndex = this . addRowParent . index + 1 ;
4100
- // ensure adding row is in view.
4101
- const shouldScroll = this . navigation . shouldPerformVerticalScroll ( newRowIndex , - 1 ) ;
4102
- if ( shouldScroll ) {
4103
- this . navigateTo ( newRowIndex , - 1 ) ;
4104
- }
4105
- const row = this . getRowByIndex ( newRowIndex ) ;
4106
- const cell = row . cells . find ( c => c . editable ) ;
4105
+ this . _pipeTrigger ++ ;
4106
+ this . cdr . detectChanges ( ) ;
4107
+ if ( isInPinnedArea ) {
4108
+ this . calculateGridHeight ( ) ;
4109
+ }
4110
+ const newRowIndex = this . addRowParent . index + 1 ;
4111
+ // ensure adding row is in view.
4112
+ const shouldScroll = this . navigation . shouldPerformVerticalScroll ( newRowIndex , - 1 ) ;
4113
+ if ( shouldScroll ) {
4114
+ this . navigateTo ( newRowIndex , - 1 ) ;
4115
+ }
4116
+ const row = this . getRowByIndex ( index + 1 ) ;
4117
+ const cell = row . cells . find ( c => c . editable ) ;
4118
+ if ( cell ) {
4107
4119
cell . setEditMode ( true ) ;
4108
4120
cell . activate ( ) ;
4109
- } ) ;
4110
- this . _pipeTrigger ++ ;
4111
- this . notifyChanges ( ) ;
4121
+ }
4112
4122
}
4113
4123
4114
4124
/**
@@ -4404,6 +4414,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
4404
4414
this . endEdit ( true ) ;
4405
4415
this . selectionService . clearHeaderCBState ( ) ;
4406
4416
this . summaryService . clearSummaryCache ( ) ;
4417
+ this . cdr . detectChanges ( ) ;
4407
4418
}
4408
4419
4409
4420
// TODO: We have return values here. Move them to event args ??
@@ -6594,9 +6605,11 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
6594
6605
return ;
6595
6606
}
6596
6607
if ( commit ) {
6597
- this . onRowAdded . pipe ( first ( ) ) . subscribe ( rowData => {
6608
+ this . onRowAdded . pipe ( first ( ) ) . subscribe ( ( args : IRowDataEventArgs ) => {
6609
+ const rowData = args . data ;
6610
+ const pinnedIndex = this . pinnedRecords . findIndex ( x => x [ this . primaryKey ] === rowData [ this . primaryKey ] ) ;
6598
6611
// A check whether the row is in the current view
6599
- const viewIndex = this . findRecordIndexInView ( rowData ) ;
6612
+ const viewIndex = pinnedIndex !== - 1 ? pinnedIndex : this . findRecordIndexInView ( rowData ) ;
6600
6613
const dataIndex = this . filteredSortedData . findIndex ( data => data [ this . primaryKey ] === rowData [ this . primaryKey ] ) ;
6601
6614
const isInView = viewIndex !== - 1 && ! this . navigation . shouldPerformVerticalScroll ( viewIndex , 0 ) ;
6602
6615
const showIndex = isInView ? - 1 : dataIndex ;
@@ -6605,6 +6618,9 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
6605
6618
this . gridAPI . submit_add_value ( ) ;
6606
6619
this . gridAPI . addRowToData ( row . data , this . addRowParent . asChild ? this . addRowParent . rowID : undefined ) ;
6607
6620
this . crudService . endRowEdit ( ) ;
6621
+ if ( this . addRowParent . isPinned ) {
6622
+ this . pinRow ( row . id ) ;
6623
+ }
6608
6624
this . addRowParent = null ;
6609
6625
} else {
6610
6626
this . crudService . exitCellEdit ( ) ;
@@ -6615,7 +6631,7 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
6615
6631
this . _pipeTrigger ++ ;
6616
6632
if ( ! this . cancelAddMode ) {
6617
6633
this . cdr . detectChanges ( ) ;
6618
- this . onRowAdded . emit ( row . data ) ;
6634
+ this . onRowAdded . emit ( { data : row . data } ) ;
6619
6635
}
6620
6636
}
6621
6637
@@ -6640,6 +6656,10 @@ export abstract class IgxGridBaseDirective extends DisplayDensityBase implements
6640
6656
return this . dataView . findIndex ( data => data [ this . primaryKey ] === rec [ this . primaryKey ] ) ;
6641
6657
}
6642
6658
6659
+ protected getUnpinnedIndexById ( id ) {
6660
+ return this . unpinnedRecords . findIndex ( x => x [ this . primaryKey ] === id ) ;
6661
+ }
6662
+
6643
6663
/**
6644
6664
* @hidden
6645
6665
*/
0 commit comments